首页 > 解决方案 > 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

标签: python-3.xpython.net

解决方案


推荐阅读