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

Cannot set subclass using strongly typed update builder

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.6
    • Affects Version/s: 1.5
    • Component/s: None
    • Labels:

      A BsonSerializationException is thrown when attempting to use the strongly typed update builder to set a subclass type. The following code reproduces the issue:

      [BsonKnownTypes(typeof(B))]
      public abstract class A
      {
      
      }
      
      public class B : A
      {
      
      }
      
      public class C
      {
          [BsonElement("a")]
          public A A { get; set; }
      }
      
      class Program
      {
          static void Main(string[] args)
          {
              var b = new B();
      
              var s = Update.SetWrapped("a", b);
              var t = Update<C>.Set(c => c.A, b); // throws BsonSerializationException
          }
      }
      

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            ashitanojoe Joe Waller
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: