Reputation: 1220
we are establishing connection from python to .net VB code. We successfully created DLL in VB, and we can import it to python using CLR. The class from DLL is imported and all the methods are visible. However when we call a method we fail with TypeErrors - even method with no arguments fails.
PS. The other (standard) VB methods work fine (i.e. from System import String a=String("Some string")
)
PS2. The code written in C# also works fine with this method
Python code to connect with .dll:
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
import os,sys
import site
scriptPath=r"E:\Dropbox\SISTeMA\TRE development\TRE Add-In\visum\Visum_VB_interactions\From PTV\VisumNetAddIn\32Bit"
assemblyPath=r"E:\Dropbox\SISTeMA\TRE development\TRE Add-In\visum\Visum_VB_interactions\Interact\bin\Debug\Interact.dll"
site.addsitedir(scriptPath)
import clr
import System
assemblyPath = os.path.join(scriptPath,assemblyPath)
site.addsitedir(os.path.dirname(assemblyPath))
assemblyFile,extension = os.path.splitext(os.path.basename(assemblyPath))
clr.AddReference(assemblyFile)
from Interact import Interact_Class
VB .net class compiled to dll:
Imports System
Public Class Interact_Class
Public s As String
Public Sub give_me()
s = "got it"
End Sub
Public Sub give_me_sth(ByVal sth As String)
s = sth
End Sub
Public Function I_will_give_you() As String
Return "Here You go"
End Function
End Class
Python calls:
from Interact import Interact_Class
print Interact_Class.give_me
Interact_Class.give_me()
from System import String
s=String("I will give You")
print Interact_Class.give_me_sth(s)
print Interact_Class.I_will_give_you()
The resulting errors:
Interact_Class.give_me()
TypeError: not enough arguments
print Interact_Class.give_me_sth(s)
TypeError: No method matches given arguments
print Interact_Class.I_will_give_you()
TypeError: not enough arguments
Thanks a lot!
Upvotes: 3
Views: 2951
Reputation: 7344
In your Python code, you are using the VB class as though it is a static class in C# terms, or a module in VB.Net terms.
You need to create an instance of it in python and then call the methods on the instance, not the class definition.
Upvotes: 3