Skip to content

Enums now don't convert to UInt32 in 3.0.0rc4 #1913

Description

@Pcres91

Environment

  • Pythonnet version: 3.0.0rc4
  • Python version: 3.9 64-bit
  • Operating System: Windows 10
  • .NET Runtime: .NET Framework 4.8.4510.0

Details

  • Describe what you were trying to get done.

I am trying passing my library's enum into a function that takes in a UInt32. Previously on Pythonnet 2.5, this conversion was done automatically. Now, I have to use System.Convert.ToUInt32(myenum.value) for conversion. Even trying UInt32(myenum.value) fails.

Is this expected behaviour? I've also noticed that printing the enumerated value now prints the name, while previously it printed the value. Is this to make it more inline with what's expected in C#? I'd still expect the UInt32 conversion to work.

clr.AddReference("MyLibrary")
from MyLibrary import eCompatibleVersion, MyClass

mylib = MyClass()
mylib.CheckCompatibility(eCompatibleVersion.BuildVersion)

Error received:

Python.Runtime.PythonException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32

The above exception was the direct cause of the following exception:

System.ArgumentException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32 in method Void CheckCompatibility(UInt32) ---> Python.Runtime.PythonException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32
   --- End of inner exception stack trace ---

The above exception was the direct cause of the following exception:

System.AggregateException: One or more errors occurred. ---> System.ArgumentException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32 in method Void CheckCompatibility(UInt32) ---> Python.Runtime.PythonException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
---> (Inner Exception #0) System.ArgumentException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32 in method Void CheckCompatibility(UInt32) ---> Python.Runtime.PythonException: MyLibrary.eCompatibleVersion value cannot be converted to System.UInt32
   --- End of inner exception stack trace ---<---


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "***", line 2, in <module>
    import load_library
  File "***", line 14, in <module>
    mylib.CheckCompatibility(eCompatibleVersion.BuildVersion)
TypeError: No method matches given arguments for IMyClass.CheckCompatibility: (<class 'MyLibrary.eCompatibleVersion'>)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions