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

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

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代码如下:

  1. import sys
  2. import clr
  3. sys.path.append(r'C:\Users\Me\Projects\Dependencies\bin')
  4. clr.AddReference('iCamstar')
  5. from iCamstar import CamstarUtil
  6. containers = []
  7. camStar = CamstarUtil(host, port, username, password, workstation)
  8. response = camStar.TestFunc(containers)
  9. print(response)

and the VB.NET code looks like so:

VB.NET 代码如下:

  1. ...
  2. Public Class CamstarUtil
  3. Public Structure MyContainer
  4. Dim ctnrName As String
  5. Dim productName As String
  6. Dim specName As String
  7. Dim description As String
  8. ...
  9. End Structure
  10. Public Sub New (ByVal host As String, ByVal port As String, ByVal user As String, ByVal pass As String, ByVal ws As String)
  11. ...
  12. End Sub
  13. Public Function TestFunc(ByVal containers As Collection(Of MyContainer))
  14. Return "Foo Bar"
  15. End Function
  16. ...

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 代码无法修改,它是一个共享库。我尝试了上面所示的方法,还尝试了以下方法:

  1. from System import Array
  2. py_array = []
  3. net_array = Array[int](py_array)
  4. 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:

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

  1. clr.AddReference('System.Collections')
  2. ...
  3. from System.Collections import *
  4. ...
  5. containers = ArrayList()
  6. ...

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:

  1. import sys
  2. import clr
  3. sys.path.append(r'C:\Users\Me\Projects\Dependencies\bin')
  4. clr.AddReference('iCamstar')
  5. from iCamstar import CamstarUtil
  6. containers = []
  7. camStar = CamstarUtil(host, port, username, password, workstation)
  8. response = camStar.TestFunc(containers)
  9. print(response)

and the VB.NET code looks like so:

  1. ...
  2. Public Class CamstarUtil
  3. Public Structure MyContainer
  4. Dim ctnrName As String
  5. Dim productName As String
  6. Dim specName As String
  7. Dim description As String
  8. ...
  9. End Structure
  10. Public Sub New (ByVal host As String, ByVal port As String, ByVal user As String, ByVal pass As String, ByVal ws As String)
  11. ...
  12. End Sub
  13. Public Function TestFunc(ByVal containers As Collection(Of MyContainer))
  14. Return "Foo Bar"
  15. End Function
  16. ...

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

  1. from System import Array
  2. py_array = []
  3. net_array = Array[int](py_array)
  4. 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:

  1. clr.AddReference('System.Collections')
  2. ...
  3. from System.Collections import *
  4. ...
  5. containers = ArrayList()
  6. ...

This did not work either

答案1

得分: 1

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

  1. from System.Collections.ObjectModel import Collection
  2. ...
  3. containers = Collection[CamstarUtil.myContainer]()
  4. ...

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

英文:

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

  1. from System.Collections.ObjectModel import Collection
  2. ...
  3. containers = Collection[CamstarUtil.myContainer]()
  4. ...

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:

确定