NullReferenceException when invoking delegate compiled from LambdaExpression

I have a delegate that is built at runtime from a LambdaExpression:

Func<T, bool> predicateDelegate = (Func<T, bool>)expression.Compile();
predicateDelegate.Invoke(item);

When I invoke it, I get a NullReferenceException with the following stack:

at lambda_0(ExecutionScope , String )
at System.Query.Func`2.Invoke(A0 arg0)
[...]

Any ideas on what I might be doing wrong

Thanks.



Answer this question

NullReferenceException when invoking delegate compiled from LambdaExpression

  • Expert

    The expression is "v != null && v.Length > 0 && v.Length < 60". The problem seems to be with "null" - the expression appears to be parsed as:

    expression = {v => AndAlso(AndAlso(op_Inequality(v, null.ToString()), GT(v.Length, 0)), LT(v.Length, 60))}


  • beedub80

    If you could describe or show the expression itself, that would be helpful.

  • NullReferenceException when invoking delegate compiled from LambdaExpression