Details
-
Bug
-
Resolution: Done
-
Critical - P2
-
None
-
None
-
None
-
None
-
Using pre-built binaries from 0.082.1.
Description
When attempting to serialize a Document with a float field, BsonWriter.TranslateToBsonType returns BsonDataType.Number for System.Single types.
In BsonWriter.WriteValue, an attempt is made to cast the object to double which is invalid since the object is of type System.Single:
case BsonDataType.Number:
writer.Write((double)obj);
return;
Here's a good article on the why http://blogs.msdn.com/ericlippert/archive/2009/03/19/representation-and-identity.aspx
One possible fix would be:
if (obj is System.Single) {
writer.Write((double)(float)obj);
} else {
writer.Write((double)obj);
}