How do you modify an assembly to trigger the AssemblyResolve event?

37 views
Skip to first unread message

Philip_L

unread,
Jun 3, 2009, 2:13:17 AM6/3/09
to mono-cecil
Hi,

I'm currently trying to modify an assembly so that I can have it
reference a dynamic assembly that will be generated at runtime, but I
can't seem to get the modified assembly to trigger an AssemblyResolve
event so that I can plug in the dynamic assembly.

So far, I've tried adding an AssemblyNameReference of the dynamic
assembly to the Module.AssemblyReferences property on the main module
of the modified assembly, but the strange part is that when I save the
AssemblyDefinition of the modified assembly back to disk and load the
modified assembly into memory, it doesn't try to trigger the
AssemblyResolve event.

According to the MSDN docs, the AssemblyResolve event is triggered
whenever the CLR is unable to find a given assembly with a particular
qualified name:

http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(vs.71).aspx

Now my question is this--did I miss something here? Is there something
that I'm doing wrong because I thought it would be looking for the
dynamic assembly if I added another AssemblyNameReference that
couldn't be resolved by the CLR. Does anyone have any ideas on how I
can get this working? Thanks in advance. :)

Jb Evain

unread,
Jun 3, 2009, 3:02:45 AM6/3/09
to mono-...@googlegroups.com
Hey Philip,

To get the AssemblyResolve event triggered, you need the JIT to
actually need the referenced assembly.

I suggest that when you load the modified assembly, you make the JIT
execute a small method that you created, containing a reference to
something which has for scope the assembly reference you added. The
JIT should then ask the runtime to resolve the reference, eventually
triggering the event.

Let me know if it works.

--
Jb Evain <j...@nurv.fr>

Reply all
Reply to author
Forward
0 new messages