BsonExtraElements with custom serializer

Hi, MongoDB Experts,

I am using MongoDB C#Driver 2.11.6. I have a class with dynamic properties. So I define it like below.

public IDictionary<string, object> DynamicProperties { get; set; }

However, when I try to customize the serialization of the DateTimeOffset type with the code below.

BsonSerializer.RegisterSerializer(new DateTimeOffsetSerializer(BsonType.String));

It works fine with fields in that class but not the DateTimeOffset data I added to the DynamicProperties at runtime.

From the source code, it looks the field has the BsonExtraElements attribute will always be serialized with the default serializer instead of the registered serializer. Is there any reasons for this? Any comments will be highly appreciated.

1 Like

I noticed the same thing with BsonExtraElements and custom serializers, I’m wondering if this is a bug?