Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BsonType.Timestamp support in ObjectSerializer #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

udda
Copy link

@udda udda commented Jan 10, 2018

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.

### 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.)

### Side effects

None
@dnickless
Copy link
Contributor

We are also experiencing the exact same bug - our clients cannot run our application against a replica set. Please merge this PR!

@dnickless
Copy link
Contributor

I created a JIRA ticket: CSHARP-2668

@jyemin
Copy link
Contributor

jyemin commented Jul 18, 2019

@udda

What command are you attempting to execute?

@udda
Copy link
Author

udda commented Jul 18, 2019

@jyemin I don't really remember since it happened over a year ago, but I think that every command (not queries) caused the error. There was a field named like t or _ts, of type Timestamp, containing the operation time. Not sure whether it's still there in MongoDB 4.

@jyemin
Copy link
Contributor

jyemin commented Jul 19, 2019

@udda yes, you're right. The field is indeed operationTime (as well as $clusterTime.clusterTime)

@idanbd
Copy link

idanbd commented Aug 2, 2021

I'm experiencing the same issue, wondering what's stopping this from being merged?

@BorisDog
Copy link
Contributor

Hello @idanbd,
Unfortunately this PR won't fix the failing IMongoDatabase.RunCommandAsync<object>, as BsonType.Binary is not supported by ObjectSerializer as well. The reason for this is that ObjectSerializer initially was not designed to support types which don't have direct mapping to .NET types.
Using IMongoDatabase.RunCommandAsync<BsonDodocument> instead should resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants