Pythonnet 无法调用具有集合参数的 VB.NET 函数。

huangapple go评论62阅读模式
英文:

Pythonnet unable to call VB.NET function with collection argument

问题

I'm having an issue trying to call TestFunc as I'm getting TypeError: No method matches given arguments for TestFunc.

我的代码存在问题,我试图调用 TestFunc 时出现 TypeError: No method matches given arguments for TestFunc 错误。

My python code looks like so:

我的Python代码如下:

import sys
import clr

sys.path.append(r'C:\Users\Me\Projects\Dependencies\bin')
clr.AddReference('iCamstar')

from iCamstar import CamstarUtil

containers = []
camStar = CamstarUtil(host, port, username, password, workstation)
response = camStar.TestFunc(containers)
print(response)

and the VB.NET code looks like so:

VB.NET 代码如下:

...
Public Class CamstarUtil

  Public Structure MyContainer
    Dim ctnrName As String
    Dim productName As String
    Dim specName As String
    Dim description As String
    ...
  End Structure

  Public Sub New (ByVal host As String, ByVal port As String, ByVal user As String, ByVal pass As String, ByVal ws As String)
    ...
  End Sub

  Public Function TestFunc(ByVal containers As Collection(Of MyContainer))
    Return "Foo Bar"
  End Function

  ...

The VB.NET code is not able to be modified, it is a shared library. I have tried what is shown above and tried:

VB.NET 代码无法修改,它是一个共享库。我尝试了上面所示的方法,还尝试了以下方法:

from System import Array
py_array = []
net_array = Array[int](py_array)
response = camStar.TestFunc(net_array)

and that did not work either. Any help would be appreciated! Thanks!

但也没有奏效。任何帮助都将不胜感激!谢谢!

EDIT: I have just tried doing this route:

编辑:我刚刚尝试了以下方法:

clr.AddReference('System.Collections')
...
from System.Collections import *
...
containers = ArrayList()
...

This did not work either.

这种方法也没有奏效。

英文:

I'm having an issue trying to call TestFunc as I'm getting TypeError: No method matches given arguments for TestFunc.

My python code looks like so:

import sys
import clr

sys.path.append(r'C:\Users\Me\Projects\Dependencies\bin')
clr.AddReference('iCamstar')

from iCamstar import CamstarUtil

containers = []
camStar = CamstarUtil(host, port, username, password, workstation)
response = camStar.TestFunc(containers)
print(response)

and the VB.NET code looks like so:

...
Public Class CamstarUtil

  Public Structure MyContainer
    Dim ctnrName As String
    Dim productName As String
    Dim specName As String
    Dim description As String
    ...
  End Structure

  Public Sub New (ByVal host As String, ByVal port As String, ByVal user As String, ByVal pass As String, ByVal ws As String)
    ...
  End Sub

  Public Function TestFunc(ByVal containers As Collection(Of MyContainer))
    Return "Foo Bar"
  End Function

  ...

The VB.NET code is not able to be modified, it is a shared library. I have tried what is shown above and tried:

from System import Array
py_array = []
net_array = Array[int](py_array)
response = camStar.TestFunc(net_array)

and that did not work either. Any help would be appreciated! Thanks!

EDIT: I have just tried doing this route:

clr.AddReference('System.Collections')
...
from System.Collections import *
...
containers = ArrayList()
...

This did not work either

答案1

得分: 1

我能够通过导入正确的集合类型来解决这个问题:

from System.Collections.ObjectModel import Collection
...
containers = Collection[CamstarUtil.myContainer]()
...

原来它不是一个泛型集合类型!

英文:

I was able to fix this by importing the correct Collection type:

from System.Collections.ObjectModel import Collection
...
containers = Collection[CamstarUtil.myContainer]()
...

It turned out it was not a Generic collection type!

huangapple
  • 本文由 发表于 2020年1月3日 23:39:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定