Setting Interop Nullable Int Bug

Mar 6, 2015 at 12:18 PM
There is a bug setting nullable int values in Jint 2.4.

You can see this if we run the following code -

var p = new Person
{
     Name = "Mickey Mouse"
};

_engine.SetValue("p", p);

var age = _engine.Execute("p.Age=System.Convert.ToInt32(5); p.Age;").GetCompletionValue().ToString();

This works fine if we use this property on the Person object -

public int Age { get; set; }

but we get an exception if the property is changed to -

public int? Age { get; set; }

This is the exception produced -

Invalid cast from 'System.Double' to 'System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.