I'm editing a legacy program in VB when most of my computer programming experience is in C#. The program in question compiles fine but when running I get to a certain function call to a DLL file and I get the following:
System.InvalidCastException: 'Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'.'
The arguments that are causing the issue are Dim'd As Integer. The function wants the arguments ByRef As Array. However, even when redefining the arguments As Array it says:
'Unable to cast object of type 'System.Int32[*]' to type 'System.Array'.'
EDIT
To try and give "minimal, complete, and verifiable example" as suggested by ItsPete here is some code.
I am using DA 1 OPC Wrapper DLL. This project is something I had to add a few part numbers to, not something I wrote from scratch.
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)
I think that is all that is needed. Like I said...I just expected to add a few part numbers to a drop down selection and not have to dig neck deep into debugging this so I'm kinda out of my depth.
Hans Passant that might be promising. But that looks like it is for C# or C++ and not VB. I dont know how there are many duplicates...searching for Int32[*] didn't return much between Google and Stackoverflow's own search.
And holy crap Jimi that is like a day of reading.