Up until .net 2.0 SP1 i have been able to call one dynamic method from another one. This can be achieved simply using the following emit:
il.Emit(OpCodes.Callvirt, methodToCall); // where il is an ILGenerator and methodToCall is a MethodInfo
It seems that in .Net 2.0 SP1 this has been broken. Deep down in the innards of System.Reflect.Emit the internal class DynamicILGenerator has been modified such that it now contains the following guard statement:
if (!((methodInfo is RuntimeMethodInfo) || (methodInfo is DynamicMethod)))
{
throw new ArgumentException(Environm
ent.GetRes
ourceStrin
g("Argumen
t_MustBeRu
ntimeMetho
dInfo"), "methodInfo");
}
This basically stops me running any method that is not a RunTimeMethodInfo. Most of my methods are ok, but i use DynamicMethods to map object inheritence structures from data sets (in a kind of ORM sort of fashion) I reuse the Dynamic method of the parent object when mapping child objects. (sorry if that is really confusing). I suspect there is a reason why MS have killed this functionality but i have never seen it documented. Perhaps if anyone from the MS compiler team is available they might be able to shed some light?? :)
Is there a way of calling a dynamic methods from dynamic methods, or at the very least converting a MethodInfo from a dynamic method to a RuntimeMethodInfo.
Start Free Trial