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

IAggregateFluent.Facet() fails to deserialize results if CamelCaseElementNameConvention is used

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Unknown Unknown
    • None
    • 2.12.4
    • None
    • None

    Description

      i'm trying to project to a different type inside the facet pipeline as shown below. everything works fine if i comment out the `CamelCaseElementNameConvention`.

      but throws `System.FormatException: 'Element 'AuthorName' does not match any field or property of class TestApplication.Program+AuthorDTO.'` if the convention is registered.

      here's a small repro:

      public class Author
      {
          public string FullName { get; set; }
      }

      public class AuthorDTO
      {
          public string AuthorName { get; set; }
      }

       

      ConventionRegistry.Register(
          name: "CustomConventionPack",
          conventions: new ConventionPack { new CamelCaseElementNameConvention() },
          filter: _ => true);
       
      var collection = new MongoClient("mongodb://localhost").GetDatabase("test").GetCollection<Author>("Author");
       
      await collection.Database.DropCollectionAsync("Author");
       
      await collection.InsertOneAsync(new Author { FullName = "author name" });
       
      var projectStage = PipelineStageDefinitionBuilder.Project<Author, AuthorDTO>(
          a => new AuthorDTO
          {
              AuthorName = a.FullName
          });
       
      var resultsFacet = AggregateFacet.Create<Author, AuthorDTO>("_results", new[] { projectStage });
       
      var res = await collection
          .Aggregate()
          //.AppendStage(projectStage)
          .Facet(resultsFacet)
          .ToListAsync();
       
      var authorName = res[0].Facets[0].Output<AuthorDTO>()[0].AuthorName;

       

      it even works fine with `.AppendState()` and the problem only occurs with `.Facet()`

       

      Attachments

        Activity

          People

            robert@mongodb.com Robert Stam
            djnitehawk83@gmail.com Damith G
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: