Hello everyone,

I have a little issue with mono.cecil that I thought I might ask
here.. So basically my main goal i'm trying to achieve is to inject an
event handler + a method to handle the event. The event handler I want
to create is: ThreadExceptionEventHandler and this is how I do it with
my ILProcessor:

            ilProc.InsertBefore(ilProc.Body.Instructions[0],
ilProc.Create(OpCodes.Ldnull));
            ilProc.InsertBefore(ilProc.Body.Instructions[1],
ilProc.Create(OpCodes.Ldftn, globalExcMethod));
            ilProc.InsertBefore(ilProc.Body.Instructions[2],
ilProc.Create(OpCodes.Newobj,
asmDef.MainModule.Import(typeof(ThreadExceptionEventHandler).GetConstructor(new
Type[] { typeof(Object), typeof(IntPtr) }))));
            ilProc.InsertBefore(ilProc.Body.Instructions[3],
ilProc.Create(OpCodes.Call,
asmDef.MainModule.Import(typeof(Application).GetMethod("add_ThreadException",
new Type[] { typeof(ThreadExceptionEventHandler) }))));

But when running the finished assembly in PEVerify with the /IL
parameter it gives me this:

"Unable to resolve token." on offset 0x0007 (newobj instance void
[System]System.Threading.ThreadExceptionEventHandler::.ctor(object,
native int))

How do I solve this issue, or is there something i'm completely
missing out here?

Thanks in advance,
UbbeLoL

-- 
--
mono-cecil

Reply via email to