Hey Philip,

On 6/3/09, Philip_L <[email protected]> wrote:
>
>  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. :)

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  <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to