Specified cast is not valid
Trying to call a legacy VB6 control and get the following error at runtime. Code compiles clean.
An unhandled exception of type 'System.InvalidCastException' occurred in TestPredict.exe
Additional information: Specified cast is not valid.
Code --->
VB6 Active X
Public Function GetConcentration(ByRef Values As Variant, ByRef Size As Long)
Dim tValues() As Double
If fPredict = True Then
Size = dGetItemSize(hCal, "concentration")
If Size = 0 Then
GetConcentration = -3 'if value not available
Else
ReDim tValues(1 To Size)
GetConcentration = dCopyItem(hCal, tValues(1), "concentration", Size)
GetConcentration = 0 'success
Values = tValues
End If
Else
GetConcentration = -2 'if prediction not available
End If
End Function
C# call --->
object fValues = new double();
err = IQPredict.GetConcforCSharp(ref fValues, ref size);
errlabel.Text = Convert.ToString(err);
double[] fval = new double[size];
fval[0] = ((double[])fValues)[0];