-
Type: Bug
-
Resolution: Duplicate
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
Summary
After upgrading to driver 2.19 we noticed integration test starts failing. The reason is in how the driver changed serialization of Decimal when saved as object.
We have a .NET type that has a type Value that contains an Object, then we can store different type and Bson Serialization does the magic. With old version of the driver here is how data is stored in MongoDb
"Value" : {
"_t" : "System.Decimal",
"_v" : "12"
},
When the data is deserialized we have a System.Decimal with value 12 in the property. Upgrading to 2.19 version of the driver we have this in the database
"Value" : NumberDecimal("12"),
And the problem is that after deserialization we have value property with an object of type MongoDb.Bson.Decimal128. This breaks the software because it cannot be casted to decimal.
As you can see the check "is Decimal" fails also it cannot be casted to Decimal, but we need to use Convert.ToDecimal(). This is actually breaking our software that is based on pure .NET type checking.
From my point of view Serialization is broken because I save object with a decimal and I got back object of Bson.Decimal128.
Version of driver 2.19
How to Reproduce
MongoTest sut = new MongoTest() { Value = 12M };
Console.WriteLine(sut.Value is Decimal);
var serialized = sut.ToBson();
var deserialized = BsonSerializer.Deserialize<MongoTest>(serialized);
Console.WriteLine(deserialized.Value is Decimal);
public class MongoTest
{ public Object Value \{ get; set; }}
As you can see from the above code, I serialize an object with a decimal in the Value property, when I deserialize I have an internal class that is not Decimal. This actually breaks serialization.
- is duplicated by
-
CSHARP-4648 Standardize handling of decimal vs Decimal128
- Closed
- is related to
-
CSHARP-4648 Standardize handling of decimal vs Decimal128
- Closed