【问题标题】:(Python) Using pythonnet to call a DLL function (C#) which expects Type ArrayList(Python) 使用 pythonnet 调用需要类型 ArrayList 的 DLL 函数 (C#)
【发布时间】:2018-12-05 23:00:20
【问题描述】:

我试图从 DLL 中运行名为“functionName”的函数,同时从 python 项目中调用它。我已经控制了许多 DLL 的函数,但是在运行“functionName”时,我相信我对 pythonnet 的 C# 数组列表的列表实现存在问题。

我试图调用的 DLL 中的行

public int functionName(ArrayList data)

目前我尝试通过以下方式创建一个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)

结果一直是:

TypeError:  No method matches given arguments

我尝试了很多不同的方法来解决这个问题,我相信问题可能属于 System.Collections.Generic.List 与 C# 的预期类型 ArrayList 不匹配。

任何帮助将不胜感激。

编辑#1

我发现还有一个:

System.Collections.ArrayList()

但这并没有解决方法匹配给出参数的问题

【问题讨论】:

标签: c# python .net overloading python.net


【解决方案1】:

解决方案是使用 python 调用一个用 C# DLL 编写的函数,该函数从第一个 dll 中获取类型和函数。

烦人但不确定如何从 python 引用在 C# dll 中创建的自定义类型。

【讨论】:

    猜你喜欢
    • 2021-06-14
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多