If a POCO has two fields where one name starts with the others name, any projection that uses these names will fail to render.
Repro:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
public class Person
{
public string FirstName { get; set; }
public string FirstNamePreferred { get; set; }
public string LastName { get; set; }
}
class Program
{
static void Main(string[] args)
{
var m = new MongoClient("mongodb://noused");
var coll = m.GetDatabase("test").GetCollection<Person>("foo");
var queryDefn = Builders<Person>.Filter.Eq(x => x.FirstName, "John");
var serializer = BsonSerializer.SerializerRegistry.GetSerializer<Person>();
// WORKING
var query = coll.Find(queryDefn).Project(x => new Person { FirstName = x.FirstName, LastName = x.LastName });
var render = query.Options.Projection.Render(serializer, BsonSerializer.SerializerRegistry).Document;
if (render == null || render.ToString() != "{ \"FirstName\" : 1, \"LastName\" : 1, \"_id\" : 0 }")
throw new Exception("Projection does not match");
// NOT WORKING
query = coll.Find(queryDefn).Project(x => new Person { FirstName = x.FirstName, FirstNamePreferred = x.FirstNamePreferred });
render = query.Options.Projection.Render(serializer, BsonSerializer.SerializerRegistry).Document;
if (render == null || render.ToString() != "{ \"FirstName\" : 1, \"FirstNamePreferred\" : 1, \"_id\" : 0 }")
throw new Exception("Projection does not match");
}
}
The issue appears to arise from this check in FindProjectionTranslator.