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

Default BsonSerializationArgs sometimes has null NominalType

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.11.0
    • Affects Version/s: 2.10.0
    • Component/s: Serialization
    • None

      When BsonSerializationArgs is not provided the default value will sometimes have a null value for the NominalType.

      This can result in an undesired `_t` discriminator value.

      Reproduction:

      namespace ConsoleApplication
      {
          public class C
          {
              public int X { get; set; }
          }
      
          public class Program
          {
              public static void Main()
              {
                  var c = new C { X = 1 };
      
                  using (var stringWriter = new StringWriter())
                  using (var writer = new JsonWriter(stringWriter))
                  {
                      BsonSerializer.Serialize(writer, c);
                      var json = stringWriter.ToString();
                  }
              }
          }
      }
      
      

      Results in:

      "{ \"_t\" : \"C\", \"X\" : 1 }"
      

      But the `_t` is not supposed to be there.

       

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: