I am trying to create an expression tree. I need to read data from a data table and check its columns. The columns to be checked and also the number of columns to be checke
It means the method call you're trying to represent is a static one, but you're giving it a target expression. That's like trying to call:
Thread t = new Thread(...);
// Invalid!
t.Sleep(1000);
You're sort of trying to do that in expression tree form, which isn't allowed either.
It looks like this is happening for the Field
extension method on DataRowExtensions
- so the "target" of the extension method needs to be expressed as the first argument to the call, because you actually want to call:
DataRowExtensions.Field(row, col);
So you want:
inner = Expression.Call(mi, rowexp, colexp);
That will call this overload which is the way to call a static method with two arguments.