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

2024-04-19 00:32:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试调用TestFunc时遇到了问题,因为我得到了TypeError: No method matches given arguments for TestFunc。你知道吗

我的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)

以及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

  ...

那个VB.NET版代码无法修改,它是一个共享库。我已经尝试了上面所示的内容并尝试了:

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

这也不管用。任何帮助都将不胜感激!谢谢!你知道吗

编辑:我刚刚试过这样做:

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

这也不管用


Tags: 代码fromimportstringresponseaspublicarray
1条回答
网友
1楼 · 发布于 2024-04-19 00:32:16

我可以通过导入正确的集合类型来解决此问题:

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

原来它不是一个通用的集合类型!你知道吗

相关问题 更多 >