Setting Array Values in Dynamics NAV 2018

I built a class library application-dll in C# with the class definition below:
namespace Microsoft.Dynamics.NAV.NAVInteropHelper
{
   public class WrapDecimalConvert
   {
      public static Type GetTypeofDouble()
      {
        return typeof(decimal);
      }
   }
}

I added the dll to the application, declared the following variable in my globals
Name      DataType    Subtype   Length
varArray  DotNet    System.Array.'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'  
varDotNet DotNet    Microsoft.Dynamics.Nav.NavInteropHelper.WrapDecimalConvert.'NavInteropHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

Then in my code, I have the following
arraySize := 10; 
// Creates an instance of the .NET Framework array that contains the decimal type.  
varArray := varArray.CreateInstance(GETDOTNETTYPE(varDotNet.WrapDecimalConvert()), arraySize);
// Clears the object instance because it is no longer used.  
CLEAR(varDotNet); 
// Sets the data in the array.
FOR i := 0 TO (arraySize -1) DO
varArray.SetValue(i+100.0,i);

Everything seems to be fine but upon calling the function, I got this error
A call to Microsoft.Dynamics.Nav.Runtime.NavDotNet[].SetValue failed with this message: Object cannot be stored in an array of this type.
Sign In or Register to comment.