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

Abstract getter confuses auto property mapping

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.2
    • Component/s: Serialization
    • None
    • Environment:
      Windows

          [BsonDiscriminator(RootClass = true)]
          [BsonKnownTypes(typeof(Apple))]
          [BsonIgnoreExtraElements]
          public abstract class Fruit {
             [BsonIgnore]        
             public abstract string Color { get; }    
          }
      
          [BsonIgnoreExtraElements]
          public class Apple : Fruit 
          {
              [BsonConstructor]
              public Apple( int seeds ) {
                  Seeds = seeds;
              }
      
              public int Seeds { get; }
              
              [BsonIgnore] 
              public override string Color => "Red";
          }
      

      Throws exception: 

      BsonSerializationException : Member 'Seeds' is not mapped.

       

      The same occurs if we use a hardcoded base constructor argument instead of an abstract property

       [BsonConstructor] 
       public Apple(int seeds) : base ( color: "Red" )
       {
          Seeds = seeds; 
       }
      

       

       

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            mjrmua@gmail.com Murray Long
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: