[CSHARP-2984] Abstract getter confuses auto property mapping Created: 01/Mar/20  Updated: 11/Nov/20  Resolved: 11/Nov/20

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.10.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Murray Long Assignee: Dmitry Lukyanov (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Issue Links:
Duplicate
duplicates CSHARP-3240 ImmutableTypeClassMapConvention is ig... Closed

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

 

 



 Comments   
Comment by Robert Stam [ 11/Nov/20 ]

The fix for CSHARP-3240 is also a fix for this issue.

Since this issue has been marked as a duplicate of CSHARP-3240 you can follow the CSHARP-3240 ticket to see which release this fix will be in.

Comment by Robert Stam [ 26/Oct/20 ]

The root cause is that the ImmutableTypeClassMapConvention is not considering all constructors.

See CSHARP-3240.

Generated at Wed Feb 07 21:44:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.