简体   繁体   English

(Python)使用pythonnet调用需要类型为ArrayList的DLL函数(C#)

[英](Python) Using pythonnet to call a DLL function (C#) which expects Type ArrayList

I am trying to run a function named "functionName" from a DLL while calling it from a python project. 我试图从python项目中调用它时,从DLL运行一个名为“ functionName”的函数。 I already have control over many of the DLL's functions but when running "functionName" I believe I have issues with pythonnet's List implementation of C#'s Array List. 我已经可以控制许多DLL的功能,但是运行“ functionName”时,我相信pythonnet的C#数组列表的List实现存在问题。

The line from the DLL which I am trying to call 我试图调用的DLL中的行

public int functionName(ArrayList data)

Currently I have tried to create a python ArrayList through: 目前,我已尝试通过以下方式创建python ArrayList:

from System import Int32
from System import Array

data1 = [Int32(x) for x in data1]                # data1 is a list
data1 = Array[Int32](data1)                      # ArrayList Expecting 8x Arrays to be added

import clr
clr.AddReference('System.Collections')
from System.Collections.Generic import List      # Avoids Deprecation

Py_Array = System.Collections.Generic.List[Array[Int32]]()
Py_Array.Add(data1)
...
Py_Array.Add(data1)                              # 8 times total

DLL.functionName(Py_Array)

The outcome has always been: 结果一直是:

TypeError:  No method matches given arguments

I have tried a lot of different ways to fix this, and I believe the issue may belong to System.Collections.Generic.List does not match the expected type of ArrayList for C#. 我尝试了许多不同的方法来解决此问题,并且我认为问题可能属于System.Collections.Generic.List与C#的ArrayList的预期类型不匹配。

Any help would be appreciated. 任何帮助,将不胜感激。

Edit #1 编辑#1

I found that there is also a: 我发现还有一个:

System.Collections.ArrayList()

But this has no solved the issue for Method Matching giving Arguments 但这并没有解决方法匹配给定参数的问题

Solution was to use python to call a function which was written in a C# DLL which takes the types and functions from the first dll. 解决方案是使用python调用在C#DLL中编写的函数,该C#DLL从第一个dll获取类型和函数。

Annoying but not sure how else to reference custom types created in C# dlls from python. 烦人但又不确定如何引用来自python的C#dll中创建的自定义类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM