Hello,
I think there is a problem with the generation of the parsed expression in version 2.0 when it comes to boxed types (most notably in DynamicObject instances). For example, the following expression works:
((decimal)e.AmountToWithdraw) > 10m
while the following does not:
e.AmountToWithdraw > 10m
where e is DynamicObject descendant, AmountToWithdraw is a dynamic property (always boxed by the DynamicObject implementation). The later throws the following error:
System.InvalidOperationException: The binary operator GreaterThan is not defined for the types 'System.Object' and 'System.Decimal'.
at System.Linq.Expressions.Expression.GetComparisonOperator(ExpressionType binaryType, String opName, Expression left, Expression right, Boolean liftToNull)
at System.Linq.Expressions.Expression.GreaterThan(Expression left, Expression right, Boolean liftToNull, MethodInfo method)
at ExpressionEvaluator.ExpressionHelper.GetBinaryOperator(Expression le, Expression re, ExpressionType expressionType)
at ExpressionEvaluator.ExpressionHelper.BinaryOperator(Expression le, Expression re, ExpressionType expressionType)
at ExpressionEvaluator.ExprEvalParser.relational_expression()
at ExpressionEvaluator.ExprEvalParser.equality_expression()
at ExpressionEvaluator.ExprEvalParser.and_expression()
at ExpressionEvaluator.ExprEvalParser.exclusive_or_expression()
at ExpressionEvaluator.ExprEvalParser.inclusive_or_expression()
at ExpressionEvaluator.ExprEvalParser.conditional_and_expression()
at ExpressionEvaluator.ExprEvalParser.conditional_or_expression()
at ExpressionEvaluator.ExprEvalParser.null_coalescing_expression()
at ExpressionEvaluator.ExprEvalParser.conditional_expression()
at ExpressionEvaluator.ExprEvalParser.non_assignment_expression()
at ExpressionEvaluator.ExprEvalParser.expression()
at ExpressionEvaluator.AntlrParser.Parse(Expression scope, Boolean isCall)
at ExpressionEvaluator.ExpressionCompiler.BuildTree(Expression scopeParam, Boolean isCall)
at ExpressionEvaluator.CompiledExpression.Compile()
It is evident that the created expression is not explicitly unboxed before calling GreaterThan().
N.B. The problem appears only if the DynamicObject travels over the wire (WCF) and is irrelevant to the underlying implementation. Locally, in the same assembly/test case, everything works fine. I guess that has to do more with the garbage collection than to
the actual types created.
Some additional notes:
