C# BsonTypeMapper Guid change in behavior between 2.x and 3.0

As far as I can tell, there’s no documentation about this. I know about the GuidSerializer changes, this is different. In the 2.x line, BsonTypeMapper has a mapping for Guid in __fromMappings. In the 3.x line, there is no such mapping.

What is the expected implementation in the new versions?

Also, this caused failures while compilation succeeds. There should be some documentation about the changes regardless of how to bridge the implementation.

Hi @Joel_R, thanks a lot for your message.

The reason why the conversion to/from Guid has been removed from BsonTypeMapper is because of the changes that have been done to the serialization of Guid as reported also here.
The main point is that now Guid don’t have a default representation anymore, so that must be explicitly set, and for this reason we can’t provide an automatic mapping in BsonTypeMapper as before, but you can still convert Guids to BsonValue by using the constructor of BsonBinaryData, for example:

var bsonVal = new BsonBinaryData(guid, GuidRepresentation.Standard);

I hope that this helped with your doubts. If not, let me know about your use case and I can hopefully provide some better insights.

1 Like

This was helpful, thank you for your guidance.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.