Hello everyone,

I just started using Cecil and it's a really powerful tool. Though I have 
got an issue with importing exceptions from a try-catch-block properly. All 
the other types seem to work fine, but exceptions use to cause trouble.

What I basically have is a chunk of IL from another assembly that throws an 
Excetion:

IL_0000: nop
IL_0001: nop
IL_0002: ldstr "test"
*IL_0007: newobj System.Void System.Exception::.ctor(System.String)*
IL_000c: throw
IL_000d: stloc.0
...

I then export the instruction's operand, which is the 
Exception(String,String) constructor, and declaring type, which is 
System.Exception, through looking it up:

MethodDefinition def = (inst.Operand as MethodReference).Resolve();
if (def.IsConstructor) {
TypeDefinition classDef = (inst.Operand as 
MethodReference).DeclaringType.Resolve();
targetAssembly.MainModule.Import(classDef);
MethodDefinition ctorDef = GetConstructor(classDef, def);
newInst = proc.Create(inst.OpCode, 
targetAssembly.MainModule.Import(ctorDef));
}

This works so far but when I call targetAssembly.Write(...) it raises the 
following exception:

Error: System.ArgumentException: Member 'System.Exception' is declared in 
another module and needs to be imported
  at Mono.Cecil.MetadataBuilder.LookupToken(IMetadataTokenProvider 
provider) in Mono.Cecil\AssemblyWriter.cs:line 1967.

This doesn't seem to happen with anything else but exceptions. I'd be 
really happy for any ideas on what I might do wrong :-)

-- 
-- 
--
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