[CSHARP-2271] ObjectSerializer should support deserializing all BSON types Created: 15/May/18 Updated: 10/Nov/22 Resolved: 10/Nov/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.5, 2.5.1, 2.6.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Chad Kreimendahl | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
We've brought up a purely fresh 3.6.3 (now 3.6.4) mongo database from scratch. Having tried with 2.5 through 2.6... When attempting to test our connection, in which we simply run a "ping" command when connecting, we're getting the following exception about Timestamp BSON type not being supported:
{{ObjectSerializer does not support BSON type 'Timestamp'.: at }} |
| Comments |
| Comment by Robert Stam [ 16/May/18 ] | |||
|
A document that has been read from the database must be able to be saved back to the database. Mapping a BSON timestamp to a .NET DateTime or an Int64 would result in the value changing when it was saved back to the database. So BsonTimestamp is the appropriate type to use.
| |||
| Comment by Chad Kreimendahl [ 16/May/18 ] | |||
|
You might also consider allowing to it cast as a "long" | |||
| Comment by Chad Kreimendahl [ 16/May/18 ] | |||
|
That should work. Is there any value in converting it to a DateTime, or would that cause issues going back the other way (saving it once modified)? | |||
| Comment by Robert Stam [ 16/May/18 ] | |||
|
I think what you are doing (using dynamic/object as the TResult for RunCommand) is perfectly reasonable. It's just that the original vision for ObjectSerializer was that it would only convert BsonValues to standard .NET types. Based on your use case I now believe ObjectSerializer should support all BsonValue types, even if it means using types that are in the driver instead of standard .NET types. For example, when a BSON timestamp is encountered ObjectSerializer could return an instance of BsonTimestamp. | |||
| Comment by Chad Kreimendahl [ 16/May/18 ] | |||
|
You've got it. That's nearly identical to our command, though the original was doing a "dynamic" vs an "object". For some reason, it's not an issue against databases that were previously. It appears that there was a change in 3.6 that must require some compat update to trigger. 3.4 ping just returns ok. 3.6 ping returns some stats. We're not using, nor would we ever have a use for Timestamp (vs DateTime), so all of these issues would only occur for us with system calls... of which there are many. We had been just taking them as "dynamic" to make our lives easier. It seems as if this is now ill advised? | |||
| Comment by Robert Stam [ 15/May/18 ] | |||
|
One way I can trigger this exception is:
This can be worked around using RunCommand<BsonDocument> instead of RunCommand<object>. | |||
| Comment by Robert Stam [ 15/May/18 ] | |||
|
Not sure what you mean by "a simple ping command". Can you provide a code snippet that can be used to reproduce this? Thanks! |