Problem While mutating NestedTypes.

May 21, 2009 at 12:17 PM
Edited May 21, 2009 at 1:52 PM

Hello,
I have a following class:

public class Class1
{
   public sealed class MyNestedClass
   {
       private delegate void Method1Delegate();

       private Method1Delegate vMethod1=null;

       private IBuilderContext bcContext;

       public MyNestedClass(IBuilderContext AContext) //Context is the class from Microsoft.Practices.Unity.
       {
         bcContext=AContext;
         vMethod1=AContext.Locator.Get<Class1>().Method1;
       }

       public void Invoke()
       {
                
         vMethod1.Invoke();
       }
   }
   public void Method1()
   {
      
   }
}

Next I am mutating an existing assembly adn to one of its Types I am adding all the members of the above Type i.e. "Class1".
I have changed the "ContainingtypeDefinition" of all the added members to the new Type.
Also I have added "MyNestedClass" and "Method1Delegate" into the mutated assembly's AllTypes.

Now I write this mutated assembly using PEWriter and this execution happens without any exception.
But when I checked this new dll in the reflector it showed me as follows:

public class Newtype
{
   public sealed class MyNestedClass
   {
        // Fields
        private IBuilderContext bcContext;
        private Method1Delegate vMethod1;

        // Nested Types
        private delegate ??? Method1Delegate(???);

       //Here the ctor and Invoke method both are missing.
   }

}

I dont understand the "???". Also one thing to note is Just like Class1 I have another Class2 with and NestedClass and a Delegate say Method2Delegate declared in the NestedClass.When I checked in the Reflector I found that the ctors (with IBuilderContext ) and the Invoke methods for both the Nestedtypes(of Class1 and Class2) are below the Method2Delegate and are missing from their right place as you can see above. I really dont know how they went there coz while debugging I checked and I found that uptil I pass the muatated Assembly to PEWriter all methods are in place.Where do they shift their positions I dont know.

The interesting part is that now when I load this new assembly the Method2Delegate appears in its AllTypes which is ok but its methods property shows the ctors(with IBuilderContext ) and Invoke methods of all the NestedTypes which is strange.!!!
Have I done something wrong or am I missing some steps.
I have been struggling for 3 days now but I am able to figure it out.
Please help with the same.



Thanx in advance.
Purva.

Coordinator
May 21, 2009 at 4:14 PM

It is a bit hard to speculate on what is happening based only on your description. Could you make a small sample program that demostrates the problem and attach it to an issue?

While Reflector is a great way to look at valid metadata, ildasm is probably more useful to track down metadata errors.

May 22, 2009 at 1:04 PM

Hello there,
I wanted to update you with the fact that I was doing all the above mentioned steps in a DSL(Domain Specific Language ,if at all you are aware of) project.
I tried the same in a console app and it worked correctly. Then I did "Reset Experimental Hive(DSL)" and all truned up well.It was the problem with DSL and not CCI.
My mistake..!!! I should have thought of this before.

sorry for the trouble.And thanx for the co-operation. :-)

Purva.