I use an interface to access an old application. From this application I have some "double array" which I can't access.The return type is declared as virtual dynamic. Whenever I access the array I got an exception.
On this question I found out that it may be because of the wrong indexed array. So I've tried the proposed solution but as I said I could not even access the array once without getting the exception.
Any idea on what the error could be?
Code with Hans approach:
var dataSetValues = dataSet.DoubleArray;
var result = ConvertDoubleArray(dataSetValues); // <<<<<< This is where I get an exception
public static double[] ConvertDoubleArray(Array arr)
{
if (arr.Rank != 1)
throw new ArgumentException();
var retval = new double[arr.GetLength(0)];
for (int ix = arr.GetLowerBound(0); ix <= arr.GetUpperBound(0); ++ix)
retval[ix - arr.GetLowerBound(0)] = (double) arr.GetValue(ix);
return retval;
}
Interface declaration of DoubleArray:
public virtual dynamic DoubleArray { get; set; }
Exception:
System.InvalidCastException: Unable to cast object of type 'System.Double[*]' to type 'System.Double[]'. at CallSite.Target(Closure , CallSite , VirtualEnvironmentManager , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at FormulaTestExecutor.Common.VirtualEnvironmentManager.CreateVirtualStructure(Formula formula) in D:\Develop\TFS\Main\tools\FormulaMTest\FormulaTestExecutor\FormulaTestExecutor\Common\VirtualEnvironmentManager.cs:line 55
Stacktrace of Exception:
FormulaTestExecutor.exe!FormulaTestExecutor.Common.VirtualEnvironmentManager.CreateVirtualStructure(FormulaTestExecutor.Model.Formula formula = {FormulaTestExecutor.Model.Formula}) Line 55 C# Symbols loaded. FormulaTestExecutor.exe!FormulaTestExecutor.Program.Main(string[] args = {string[0]}) Line 18 C# Symbols loaded.