- Notifications
You must be signed in to change notification settings - Fork749
Closed
Description
Environment
- Pythonnet version: 3.0.0a2
- Python version: 3.7, 3.8, 3.9, 3.10
- Operating System: Windows
- .NET Runtime: 4.7.2 framework
Details
After upgrading to pre release 3.0.0a2 version, the python int type is getting translated to PyInt instead of System.int32 inside the .NET DLL, and hence getting a unable to cast exception. this is working fine in 2.x version.
DLL method:
publicvoidDictMethod(Dictionary<string,object>paramDict){Console.WriteLine("Inside");Console.WriteLine(paramDict["index"].GetType().ToString());varindex=Convert.ToInt32((paramDict["index"]));}
Python script:
clr.AddReference("System.Collections")fromSystem.Collections.GenericimportDictionaryfromSystemimportStringfromSystemimportObjectclr.AddReference("PyTest")fromPyTestimportPyClassclassUtils(object):@staticmethoddefprepare_dict(**kwargs):dict_net=Dictionary[String,Object]()forkey_valueinkwargs.keys():dict_net.Add(key_value,kwargs[key_value])returndict_netparameters= {}parameters['index']=1net_dict=Utils.prepare_dict(**parameters)obj=PyClass()obj.DictMethod(net_dict)
Output in 3.x version:
C:\Users\Athul\Desktop>c:\Python37\python.exe pynettest.pyInsidePython.Runtime.PyIntTraceback (most recent call last): File "pynettest.py", line 50, in <module> obj.DictMethod(net_dict)System.InvalidCastException: Unable to cast object of type 'Python.Runtime.PyInt' to type 'System.IConvertible'. at System.Convert.ToInt32(Object value) at PyTest.PyClass.DictMethod(Dictionary`2 paramDict) in C:\Users\Athul\source\repos\PyTest\PyClass.cs:line 46
Output in 2.x version :
C:\Users\Athul\Desktop>c:\Python37\python.exe pynettest.pyInsideSystem.Int32C:\Users\Athul\Desktop>
Metadata
Metadata
Assignees
Labels
No labels