Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-5349

v3.0 breaks registering discriminator convention on base type

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 3.0.0
    • Component/s: Serialization
    • Dotnet Drivers

      Summary

      In our database we need to use "type" instead of "_t" for setting type discriminator. We have so far successfully done this with this code during start-up:

      
      

      BsonSerializer.RegisterDiscriminatorConvention(typeof(JsonTypedObject), new ScalarDiscriminatorConvention("type"));

      All of our types that are serialized in this way inherit from "JsonTypedObject". In version 3 of the MongoDB C# Driver running the above code no longer has any effect on the serialization output ("_t" is still used as the discriminator element name).

      I have tried to find alternative ways of registering this, but so far I have not had any success. Manually registering all classes individually is not an alternative, as we have hundreds of classes.

       

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      Repository that shows reproducible example: jizc/mongodb-discriminator-convention-issue

      Additional Background

      I believe that this commit is what caused the issue: CSHARP-5286: Add IHierarchicalDiscriminatorConvention and IScalarDisc... - mongodb/mongo-csharp-driver@f54ba02

      If you don't see this as a bug, please help us by providing an alternative way for us to achieve the "type" discriminator element name.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            jancar@attensi.com Jan Ivar Carlsen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: