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

Cannot set subclass using strongly typed update builder

    XMLWordPrintable

    Details

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

      Description

      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
          }
      }

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: