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

The memberinfo argument must be for class {ChildTestDto}, but was for {ParentTestDto}}

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.20.0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      Projecting to a POCO using constructor that is inheriting from a base POCO fails to project using the LinqProvider V3 but works fine using the LinqProvider V2. 

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      driver: 2.19.1

      How to Reproduce

      Test code: 

      public class InheritanceTest
      {
          [Fact]
          public async Task Test()
          {
              BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
              BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
              var mongoClient = new MongoClient(MongoClientSettings.FromConnectionString("mongodb://intigriti:!ntIgrit!@localhost:27017/?replicaSet=rs1"));
              var database = mongoClient.GetDatabase("testdatabase");
              var collection = database.GetCollection<TestDocument>("testdocuments");
              var id = Guid.NewGuid();
              await collection.InsertOneAsync(new TestDocument { Id = id, Name = "test" });
              var dto = await collection
                  .Find(x => x.Id == id)
                  .Project(x => new ChildTestDto(x.Id, x.Name))
                  .FirstAsync();
          }
      
          public class TestDocument
          {
              public Guid Id { get; set; }
              public string Name { get; set; }
          }
      
          public class ParentTestDto
          {
              public Guid Id { get; set; }
              public string Name { get; set; }
              public ParentTestDto(Guid id, string name)
              {
                  Id = id;
                  Name = name;
              }
          }
      
          public class ChildTestDto : ParentTestDto
          {
              public ChildTestDto(Guid id, string name) : base(id, name)
              {
                  
              }
          }
      } 

      Additional Background

      We are trying to upgrade to the latest driver version but are hitting multiple roadblocks. It feels like the LinqProvider V3 isn't production ready. Documentation with some guidelines for migration would be a nice addition. Like the V2 provider has a fall-back to in memory projection when the expression isn't supported while V3 just crashes hard.

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            arne@intigriti.com Arne Schoonvliet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: