python-3.x - Pythonnet 列表无法转换类型
问题描述
我正在使用带有 python 的 .dll 来向运动控制器发送命令。大多数请求都可以,但是在尝试以下操作时我遇到了困难:
from System.Collections.Generic import List
from System import String
result, response_list, err_string = SMC.ZT(1, List[String], "")
# The Error:
result, list_parameters, err_string = self.SMC.ZT(ctlr_address, List[String], err_string)
System.ArgumentException: Unable to convert type object 'System.RuntimeType' in type 'System.Collections.Generic.List`1[System.String]&'.
to System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
to System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
to System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
to System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
to Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo)
# Syntax from the docs:
# int ZT(int controllerAddress, out List<string> Parameters, out string errstring)
# controllerAddress: controllerAddress
# Parameters: Parameters
# errString: The failure reason
# return: 0 in success and -1 on failure
解决方案
推荐阅读
- scala - Spark Scala 上的 java.lang.NullPointerException 问题
- python - 如何将串行输入拆分为消息
- python - Matplotlib polar 未按预期绘制
- python - 没有名为“flask_sqlalchemy”的模块
- arrays - PhpUnit:如何检查所选数组元素的检查顺序
- sql - 将 nil 值分配给 driver.Value 使 driver.Value 不等于 nil
- javascript - 为什么我的 ```document.querySelector``` 无法选择按钮元素?
- javafx - 覆盖 TableCell 上的 TableRow 样式
- sql - TOP(1) vs MIN 问题 - 为什么 SQL Server 使用聚集扫描而不是寻找覆盖索引?
- html - 在 100vh / 100vw div 附近获得边界?(影响 div 的总宽度和高度)