1
Vote

VisitAndConvert<> vs. SubtreeEvaluator

description

Hi!
 
Expression may contain parts which are evaluated locally by SubtreeEvaluator in a way that the expression's type changed.
But some of those type's processing in ExpressionVisitor will call ExpressionVisitor.VisitAndConvert<> method which will throw exception like the one below in these cases:
 
Exception: System.InvalidOperationException
Message: When called from 'VisitListInit', rewriting a node of type 'System.Linq.Expressions.NewExpression' must return a non-null value of the same type. Alternatively, override 'VisitListInit' and change it to not visit children of this type.
StackTrace:
at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
at System.Linq.Expressions.ExpressionVisitor.VisitListInit(ListInitExpression node)
at System.Linq.Expressions.ListInitExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at ExpressionSerialization.Evaluator.SubtreeEvaluator.Visit(Expression exp)
at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at ExpressionSerialization.Evaluator.SubtreeEvaluator.Visit(Expression exp)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression1 node)
at System.Linq.Expressions.Expression
1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at ExpressionSerialization.Evaluator.SubtreeEvaluator.Visit(Expression exp)
at ExpressionSerialization.Evaluator.SubtreeEvaluator.Eval(Expression exp)
at ExpressionSerialization.Evaluator.PartialEval(Expression expression, Func`2 fnCanBeEvaluated)
at ExpressionSerialization.Evaluator.PartialEval(Expression expression)
 
Patch attached.

file attachments

comments