vb.net - '无法将'System.Int32[*]'类型的对象转换为'System.Int32[]'类型。'
问题描述
当我的大部分计算机编程经验都在 C# 中时,我正在用 VB 编辑一个遗留程序。有问题的程序编译得很好,但是在运行时我得到了对 DLL 文件的某个函数调用,我得到以下信息:
System.InvalidCastException: 'Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'.'
导致问题的参数是 Dim'd As Integer。该函数需要参数 ByRef As Array。但是,即使将参数重新定义为数组,它也会说:
'Unable to cast object of type 'System.Int32[*]' to type 'System.Array'.'
编辑
尝试按照ItsPete的建议给出“最小、完整和可验证的示例”,这里有一些代码。
我正在使用DA 1 OPC Wrapper DLL。这个项目是我必须添加一些零件号的东西,而不是我从头开始写的东西。
Dim ConnectedOPCServer As New OPCAutomation.OPCServer
Public OPCItemCollection As OPCAutomation.OPCItems
Public gConnectedGroup As OPCAutomation.OPCGroup
Dim ConnectedServerGroups As OPCAutomation.OPCGroups
Dim ItemServerHandles() As Integer
Dim ItemServerErrors() As Integer
Dim OPCItemIDs() As String
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect("Kepware.KEPServerEX.V5")
ConnectedServerGroups = ConnectedOPCServer.OPCGroups
gConnectedGroup = ConnectedServerGroups.Add("Group1")
gConnectedGroup.UpdateRate = 200
gConnectedGroup.IsSubscribed = True
Call Add_OPC_Items() 'This adds tags to the OPC collection by assigning elements of the OPCItemIDs array to tag names
OPCItemCollection = gConnectedGroup.OPCItems
OPCItemCollection.DefaultIsActive = True
OPCItemCollection.AddItems(ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors)
我认为这就是我们所需要的。就像我说的......我只是希望在下拉选择中添加一些零件号,而不必深入调试这个,所以我有点超出我的深度。
汉斯帕桑特可能很有希望。但这看起来像是针对 C# 或 C++ 而不是 VB。我不知道有多少重复...在 Google 和 Stackoverflow 自己的搜索之间搜索 Int32[*] 并没有返回太多。
和神圣的废话吉米,就像一天的阅读。
解决方案
推荐阅读
- java - 将 org.w3c.dom.Element 转换为 org.dom4j.Element
- react-native - React Native AdMob 错误:未定义不是对象(评估“_reactNative.View.propTypes.style”)
- azure - 如何连接 Azure DevOps 变量以创建新变量
- django - 在模型之外使用 Django 的 RegexValidator
- c++ - 标准库类型的赋值运算符的引用限定符
- teradata-sql-assistant - 在 SQL 助手的用户空间创建宏和视图
- git - 如果其中一个合并到主分支,那么更新从特性分支获取的姊妹子特性分支的最佳方法是什么?
- abap - SAPSQL_PARSE_ERROR 异常的有意义的错误消息
- sql - 来自不同表的值的总和并放入另一列
- scala - 如何修复此错误“未找到:值 BMValsProcessor”