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

Default BsonSerializationArgs sometimes has null NominalType

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.10.0
    • Fix Version/s: 2.11.0
    • Component/s: Serialization
    • Labels:
      None

      Description

      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.

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstam Robert Stam
              Reporter:
              rstam Robert Stam
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: