first post from newbie after having spend three days googling and reading MSDN:
From C# I'm trying to call a method in a VB dll which starts like this:
Public Function Correl(action As String, ByRef returns As Object, observation_frequency As Double) As Double(,)
Dim left As String = Strings.UCase(Strings.Trim(action))
Dim num As Double = observation_frequency
Dim objectValue As Object = RuntimeHelpers.GetObjectValue(returns)
Dim num2 As Short
Dim num3 As Short
Dim num4 As Short
Dim array As Double(,)
Dim arg_5D_0 As Short
Dim num5 As Short
' The following expression was wrapped in a checked-statement
num2 = CShort(Information.UBound(CType(objectValue, Array), 1))
num3 = CShort(Information.UBound(CType(objectValue, Array), 2))
num4 = num2 + 1
objectValue = RuntimeHelpers.GetObjectValue(returns)
array = New Double(CInt((num2 + 1)), CInt((num3 + 1)))
arg_5D_0 = 1
num5 = num2
For num6 As Short = arg_5D_0 To num5
Dim arg_65_0 As Short = 1
Dim num7 As Short = num3
For num8 As Short = arg_65_0 To num7
array(CInt(num6), CInt(num8)) = Conversions.ToDouble(NewLateBinding.LateIndexGet(objectValue, New Object()() = { num6, num8 }, Nothing))
Next
Next '...........
When calling the method from C# like this
double[] dcloses1 = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
double[,] dcloses2 = new double[,] { { 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 } };
object ocloses = (object)dcloses1; // or dcloses2
double[,] nFullMatrix = corobj.Correl("AVC", ref ocloses, (double)frequency);
I get an error from second argument (ByRef returns As Object), originating from line 12 (num2 = CShort(...) like this:
Passing single dimensional array (dcloses1), error is: "Argument 'Rank' is not valid for the array." True as it expects a N:N matrix, but at least the array is passed.
Passing two dimensional array (dcloses2), error is: "Value cannot be NULL. Parameter name: Argument 'Array' is Nothing." So seems arraya inb object is not recognized.
Seems that the method expects an array wrapped into an object as it uses GetObjectValue(), but all intents so far to hand over the needed matrix have failed.
Have called this before from Excel VBA passing variant w/o any issue, but also C# VariantWrapper has not helped.
Any idea on how to structure the object for the second argument? Any similar experience between C# and VB interop?
Update Over the last day have tried all other structures, lists, array forms I'm aware off, but somehow without any success. Still same error "Value cannot be NULL. Parameter name: Argument 'Array' is Nothing.". Any other idea I could try?