In the following snippet below:
static void Main(string[] args)
{
Expression<Func<string, bool>> equal = s => s == "test";
LambdaExpression lambda = Expression.Lambda(equal.Body, Expression.Parameter(typeof(string), "s"));
lambda.Compile();
}
Compiled method with InvalidOperationException
"variable 's' of type 'System.String' referring to scope '', but it is not defined."
While I found other similar questions, I could not understand the answers.
The LugdaExpression expression in DebugView contains the following:
.Lambda
$s == "test"
}
So, where I saw in other examples of this question, the parameter and usage do not match, this does not seem to be a problem. What am I doing wrong?
one-t source
share