Advertisement

12.17.2007 at 08:07AM PST, ID: 23028184
[x]
Attachment Details

Call a Dynamic Method from a Dynamic Method

Asked by ZenMasterZed in Reflection for .Net, .NET Framework 2.0, .NET Framework 3.x versions

Tags: dynamic, method

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(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "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
 
Loading Advertisement...
 
[+][-]12.17.2007 at 08:57AM PST, ID: 20486071

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.17.2007 at 09:10AM PST, ID: 20486183

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.03.2008 at 01:16PM PST, ID: 20576967

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.20.2008 at 08:40AM PST, ID: 20701644

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Reflection for .Net, .NET Framework 2.0, .NET Framework 3.x versions
Tags: dynamic, method
Sign Up Now!
Solution Provided By: ZenMasterZed
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628