System.InvalidCastException for nullable decimal
If I use a POCO with a nullable decimal, it looks to be stored correctly as a double, but I get an System.InvalidCastException when I try to retrieve the object.
Fetching it as a BsonDocument works fine, and using a non nullable decimal also works fine.
Changing this (in BsonMapper.Deserialize) seems to fix the immediate problem, but not sure if it breaks something else.
Before
// if is nullable, get underlying type
else if (Reflection.IsNullable(type))
{
type = Reflection.UnderlyingTypeOf(type);
}
After
// if is nullable, use underlying type
else if (Reflection.IsNullable(type))
{
return Convert.ChangeType(value.RawValue, Nullable.GetUnderlyingType(type));
}
Hi @automada, thanks for find this. Has an extra else before if after change type value. Please, compile master branch and test in your app.
Hi @mbdavid! Just tested it and it works as expected. Thanks for both resolving this so quickly and a great project!