[CSHARP-3739] IAggregateFluent.Facet() fails to deserialize results if CamelCaseElementNameConvention is used Created: 15/Jul/21  Updated: 18/Apr/22

Status: Backlog
Project: C# Driver
Component/s: None
Affects Version/s: 2.12.4
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Damith G Assignee: Robert Stam
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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()`

 


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