Serialization Issue in MongoDB.Driver 3.0.0 for C#

Hi @Krzysztof_Pajak,

Thanks for your message.

I think that actually your errors are not due to your Id field, but are caused by some other Guid field you have.

The first error you’ve seen is due to the fact that in version 3.0.0 of the driver developers are expected to be explicit about what is the format should be used for serializing/deserializing GUIDs (you can read more info about it in the documentation here). This is the same as using BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; in pre 3.0.0 versions of the driver.
For this reason, you need to specify the default format of GUIDs either by registering a GuidSerializer (like you did) or specifying an attribute on the property.

Regarding your second issue. This is happening because you’ve declared that your default representation for GUIDs should be GuidRepresentation.Standard but when deserializing some data, the driver encountered some values that were using a legacy representation, such as GuidRepresentation.CSharpLegacy, for example. In order to solve this you can either specify a differeny default GuidRepresentation like you did, or instead specify the representation of a certain property using an attribute, for example with [BsonGuidRepresentation(GuidRepresentation.CSharpLegacy)] . Of course you need to be careful because you could have some GUIDs written in a certain format and others written in another.

Hope everything was clear :slight_smile:

2 Likes