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

Abstract getter confuses auto property mapping

    XMLWordPrintable

    Details

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

      Description

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

       

       

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: