I'm trying to call a compiled LambdaExpression with the following code:
LambdaExpression exp = CreateExpression();
MethodInfo method = exp.Compile().Method;
But I receive a NullReferenceException when calling the delegate returned by Fasterflect. I've traced the exception down to the GetHashCode mehtod of the CallInfo class. It seems that the TargetType (which is initialized with the DeclaringType of the MethodInfo)
property is null. I believe that DeclaringType should be null because the method is created at runtime and is not declared in any type.
Is there another way of calling a MethodInfo in this scenario or, even better, the Delegate generated by the LambdaExpression.Compile method?