It drives me crazy.
AssemblyDefinition asm1 = AssemblyDefinition.ReadAssembly(example); AssemblyDefinition asm2 = AssemblyDefinition.ReadAssembly(example2); asm2.MainModule.Types.Add(asm1.MainModule.Types[0]);
Whenever I try to execute the above code, I get this error "The type is already attached" I decided to look at this error in the MonoCecil source, and I found that it throws this error, because Type MainMoudle is not asm2 MainModules. So I decided to copy this type to a new one.
TypeDefinition type2 = new TypeDefinition("", "type2", Mono.Cecil.TypeAttributes.Class); foreach (MethodDefinition md in asm2.Methods ) { type2.Methods.Add(md); }
And then add this type to my assembly, but it causes another error: "The specified method is not supported." Any thoughts why I get this error?
Edit: just to add, the type I'm trying to add contains some methods that use pointers. Perhaps this is a problem? As far as I know, mono supports this, but not mixed mode.
source share