In a previous question, I asked how to get a MethodInfo
from an Action delegate. This Action delegate was created anonymously (from a Lambda). The problem I'm having now is that I can't invoke the MethodInfo
, because it requires an object to which the MethodInfo
belongs. In this case, since the delegates are anonymous, there is no owner. I am getting the following exception:
System.Reflection.TargetException : Object does not match target type.
The framework I'm working with (NUnit) requires that I use Reflection to execute, so I have to play within the walls provided. I really don't want to resort to using Emit
to create dynamic assemblies/modules/types/methods just to execute a delegate I already have.
Thanks.
You already got the Method property. You'll need the Target property to pass as the 1st argument to MethodInfo.Invoke().