Difference in Tuple Serialization in C# driver 2.18 and 2.19

Hey! I recently upgraded the c# driver from 2.18 to 2.19. And Tuple Serialization in both are being done differently. Which is causing issues and bigger problem is these differences I was not able in docs. As per this document on breaking changes introduced in 2.19 for known types only Object Serializer works with tuple being a known type.

In the attached image: I have created a sample small object to repro the issue. And have shared the serialization result returned by 2 different versions of c# driver.

Could you help me, and provide me insights on how to serialize Tuple with driver 2.19 same as 2.18? for backward compatilities. Also Is there extensive list of other known types whose serialisation is being updated in 2 driver verisons.

Version 2.18 of the C# driver had no special support for ValueTuple. It was serialized like any other POCO using a class map and a class map serializer.

Version 2.19 of the C# driver added explicit support for ValueTuple, and it uses an array as the most compact representation of the tuple.

You can configure the driver to use the old behavior like this:

var tupleClassMap = BsonClassMap.LookupClassMap(typeof(ValueTuple<int, int, int, int>));
var tupleSerializer = new BsonClassMapSerializer<ValueTuple<int, int, int, int>>(tupleClassMap);
BsonSerializer.RegisterSerializer(tupleSerializer);

This code must execute during application startup, at least before any serialization is attempted. You also must repeat a variation of the above for every ValueTuple class because there is a different class depending on the number of values in the tuples and their types.