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"));
BsonSerializer.RegisterSerializer(objectSerializer);
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.
Apparently, it takes them into account automatically when you make sure you pass in the right nominal type to the corresponding Serialization functions.
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.
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.