[CSHARP-35] BsonWriter.WriteValue throws System.InvalidCastException when serializing a float field. Created: 01/Apr/10 Updated: 01/Apr/10 Resolved: 01/Apr/10 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Doug Marien | Assignee: | Sam Corder |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
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: 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) { |
| Comments |
| Comment by Sam Corder [ 01/Apr/10 ] |
|
Will be released as part of 0.82.2 |