I’m working on some internal tooling for a suite of microservices. In doing so I’ve run into an issue with the MongoDB.Driver.Linq.Linq3Implementation.Misc.SymbolTable class.
I have a layer of abstraction over the driver which uses generic type arguments to speed up some of our development. One of my newer methods will yield an array of Expression<Func<T, object>>. These expressions are the same format as the lambda operators that the driver uses; but my code is failing. It appears that building the expression with reflection myself - as opposed to using the Builders to do it - isn’t allowed. However, because I’m using a generic type argument, I can’t dynamically do this otherwise. I don’t have access in my framework to models that are used.
Expression<Func<T, object>> foo = GetAccessorExpression();
// throws an ExpressionNotSupportedException!
var bar = new ExpressionFieldDefinition<T>(foo)
.Render(BsonSerializerRegistry.getSerializer<T>(), BsonSerializer.SerializerRegistry);
I cloned the driver to find out what’s going on, and the failure is at SymbolTable.cs:
public bool TryGetSymbol(ParameterExpression parameter, out Symbol symbol)
{
foreach (var s in _symbols)
{
if (s.Parameter == parameter) // <--------- This is always false with my crafted expressions
{
symbol = s;
return true;
}
}
symbol = null;
return false;
}
If I change that conditional to:
if (s.Parameter == parameter || s.Parameter.Type == parameter.Type)
Then everything works as expected.
I can’t seem to create an issue anywhere - trying to log in yields unauthorized errors - and I’m not sure how to progress past this beyond maintaining my own fork. Am I out of luck?