I am almost at the end of my wits here and am hoping you all could help me figure this one out. I am running Anaconda Python 3.5 64 bit and compiled Python.NET anaconda package to add .NET capabilities to Python. I imported a DLL sent to me by someone and here is how my code looks like:
from __future__ import (
unicode_literals,
print_function,
division,
absolute_import
)
import clr
from System import String, Char, Int32
clr.setPreload(True)
clr.AddReference('System.Windows.Forms')
clr.AddReference(
"C:\\Program Files\\XYZ\\TTE.dll"
)
import TTE
from System.Windows.Forms import Form, Application, Button
import System
tt = TTE.TT()
form = Form()
# declaring string (not python native string) to get System.String
cdbp = String('C:\\')
sdbp = String('C:\\')
mdbp = String('C:\\')
tt.Initialize(cdbp, sdbp, mdbp, form)
'''
tt.Initialize.Overloads[
System.String, System.String, System.String, System.Windows.Forms.Form](
cdbp, sdbp, mdbp, form
)
'''
When I run the Initialize function, I get the following exception:
Traceback (most recent call last):
File "C:/Users/as/All/Code/try1.py", line 257, in <module>
tt.Initialize(cdbp, sdbp, mdbp, form)
System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'TTE.TT+ResultEnum&'.
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo)
I am fairly new to .NET and have tried googling and looking at all the stack overflow posts related to Python.NET but I dis not find the information I am looking for. Another curious thing is that the same DLL works when used in VB and fails when used in python. Why would that be?
I thought the problem was with Python.NET thinking that I am calling a different (overloaded) function named Initialize so I tried the Overloads call (in comment) and it gave me the following exception:
Traceback (most recent call last):
File "C:/Users/as/All/Code/try1.py", line 261, in <module>
System.Windows.Forms.Form](cdbp, sdbp,
TypeError: No match found for signature
Then as per recommendation, I printed the Overload and here is the output
Int32 Initialize(System.String ByRef, System.String ByRef, System.String ByRef, System.Windows.Forms.Form, ResultEnum ByRef, ResultEnum ByRef, ResultEnum ByRef)
Int32 Initialize(System.Collections.Specialized.StringCollection ByRef, System.String ByRef, System.String ByRef, System.Windows.Forms.Form, ResultEnum ByRef, ResultEnum ByRef, ResultEnum ByRef)
Int32 Initialize(System.Collections.Generic.List`1[System.String] ByRef, System.String ByRef, System.String ByRef, System.Windows.Forms.Form, ResultEnum ByRef, ResultEnum ByRef, ResultEnum ByRef)
I can clearly see why Overload is complaining, but the VB function Initialize I am targeting has declared the last three ResultEnum parameters as optional, but Python clearly requires it.
Is there a particular direction I should be looking in?