BsonType.Timestamp support in ObjectSerializer #312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Scenario
Calling
IMongoDatabase.RunCommandAsync<object>
fails when response contains values with BSON type Timestamp. This happens at every request when using replica sets.A
FormatException
is thrown saying: ObjectSerializer does not support BSON type Timestamp.Specialized serializers (like
BsonTimestampSerializer
) can't be used here, because the anonymous response type doesn't allow class mapping.Solution
Add an entry to
ObjectSerializer
type recognition code, in order to support Timestamp deserialization.That's already done for other BSON types (binary, int, decimal, array, string, objectId, etc.)
Notes
CSHARP-1162 says that Timestamp class is for internal use only, this may be the reason why it's not supported. This PR does not aim to change that.
Nevertheless,
RunCommandAsync
(and possibly other methods) just fail with collections that contain a Timestamp value. This is often out of programmers control, and the proposed change may be a painless solution.