首页 > 解决方案 > '无法将'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[*] 并没有返回太多。

和神圣的废话吉米,就像一天的阅读。

标签: vb.net

解决方案


推荐阅读