Hi Evain,

I am also getting the same error but though the method which i am calling 
is in the same dll but different namespace.
Do i need to copy the definitions in the same dll?

On Tuesday, 31 August 2010 15:34:03 UTC+5:30, nyka wrote:
>
> I currently autogenerate some code and compile it into a dll. I then 
> want to move the types in this generated dll into another dll. I have 
> tried the following but the resulting assembly is invalid. 
>
>             AssemblyDefinition originalDll = 
> AssemblyDefinition.ReadAssembly(dirname + "Original.dll" ); 
>             AssemblyDefinition generatedDll = 
> AssemblyDefinition.ReadAssembly(dirname + "Generated.dll" ); 
>
>             List<TypeDefinition> typesToMoveToOriginalDll = new 
> List<TypeDefinition>(); 
>
>             foreach (TypeDefinition type in new 
> List<TypeDefinition>( generatedDll.MainModule.Types) ) 
>             { 
>                 if (type.Name != "<Module>") 
>                 { 
>                     typesToMoveToOriginalDll.Add(type); 
>
>                     generatedDll.MainModule.Types.Remove(type); 
>                 } 
>             } 
>
>             foreach (TypeDefinition type in typesToMoveToOriginalDll) 
>             { 
>                 originalDll.MainModule.Types.Add(type); 
>             } 
>
>             originalDll.Name.Name = "Original.Modified"; 
>             originalDll.Write( dirname + "Original.Modified.dll" ); 
>
> Peverify shows the following errors: 
>
> C:\Mono\cecil\Generated\bin\Debug>peverify Original.Modified.dll 
>
> Microsoft (R) .NET Framework PE Verifier.  Version  4.0.30319.1 
> Copyright (c) Microsoft Corporation.  All rights reserved. 
>
> [IL]: Error: [C:\Mono\cecil\Generated\bin\Debug 
> \Original.Modified.dll : Original.Entity::DoSomething][offset 
> 0x00000003] 
> [found ref ('this' ptr) 'Original.Entity'][expected ref 
> 'Generated.EntityData'] Unexpected type on the stack. 
> [IL]: Error: [C:\Mono\cecil\Generated\bin\Debug 
> \Original.Modified.dll : Original.Entity::DoSomething][offset 
> 0x00000003] 
>  Field is not visible. 
> 2 Error(s) Verifying Original.Modified.dll 
>
> Reflector shows that methods from types in the original dll have been 
> aliased onto the "imported" types from the generated dll. 
>
> Is there a simple way to move types between dlls, or do I need to 
> create a new TypeDefinition in the destination dll, and copy 
> FieldDefinitions, MethodDefinitions, etc ? 
>
> If I need to copy all definitions manually, do I need to iterate 
> through all instructions of each method and correct TypeReference 
> operands. For example, if code in the generated DLL referenced types 
> in the destination DLL, references will change from: 
>
>     class [Original]Original.MyFieldType 
> to: 
>     class Original.MyFieldType 
>
> since the referenced type would now be in the same dll as the 
> "imported" generated type. 
>

-- 
-- 
--
mono-cecil
--- 
You received this message because you are subscribed to the Google Groups 
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to