Feature Request: C# driver to auto register all explicitly mapped types as allowed

With release 2.19.0 we now have to register our types in order for them to be serialized. The suggestion in the release notes here is to do the following…

var objectSerializer = new ObjectSerializer(type => ObjectSerializer.DefaultAllowedTypes(type) || type.FullName.StartsWith("MyNamespace"));

This works, however, at the company I work we explicitly register all our types using BsonClassMap.RegisterClassMap<T>(...) to avoid accidents when serializing/deserializing. Given that we’re already being explicit about the types we want registered could the library note these types and add them to the allowed types automatically.

Hi Gareth

Great minds think alike :wink:

I just raised the same feature request


Apparently, it takes them into account automatically when you make sure you pass in the right nominal type to the corresponding Serialization functions.

Do you have a link to that information? Maybe we’re not doing something correctly.

I also created the feature request in Jira here before you’d posted so that may get a bit more information

Thank you for filing this feature request. It is a reasonable idea. We will discuss it during our weekly triage meeting. Please follow CSHARP-4581 for updates.


Hi Gareth,

I did update our test suite to use the latest client, and then switched towards using the correct type-based overloads on the serializer.

our code already adds the mappings here

and then all our tests passed which previously they didn’t so I was assuming it somehow already makes the serializer “aware” of the types. That being said, it might also “just” work because internally in the client, there are many different serializer types that are being used.