I need to return an array of initialized objects from VB6 into C# using interop. My VB function looks like
Public Function CreateMyObjArray(ByVal MaxCount As Integer) As MyObj()
Dim i As Integer
Dim temparray() As MyObj
ReDim temparray(MaxCount) As MyObj
For i = 0 To MaxCount
Set temparray(i) = New MyObj
Next i
CreateMyObjArray = temparray
End Function
Now, when I call this from C# after passing in the array by
Array InData = m_MyObjGenerator.CreateMyOjbArray(5);
I get a system.argumentexceptionerror where the message is
"Exception of type 'System.ArgumentException' was thrown.\r\nParameter name: typeName@0"
I also get this error if my function has no parameters. The function works in VB from a form. Likewise, the following function returns a MyObj just fine
Public Function CreateMyObj() As MyObj
Set CreateMyObj = New MyObj
End Function
I know I can make a list of new MyObj's in the C# version and then .ToArray() it, but I would really like to get this working. Thanks.
Solution Found out how to do it. I had to use tlbimp.exe without the /sysarray flag (which VS must use internally). After that, I was able to get everything working correctly. Thanks for the help guys.