This project is read-only.

Loading referenced assemblies

Sep 23, 2011 at 5:14 PM

Hi 

While making deep copy of assembly PEFileToObjectModel loads referenced assemblies to host and those assemblies are loaded and cached as dummy. Then I try to load one of those assemblies through LoadAssembly on default host. Even if my AssemblyIdentity defines location of existing dll I get dummy. LoadUnitFrom works fine. I noticed that first method retrieves assembly from cache. Shouldn't it replace dummy with correct reference supplied on later time? Or is there some event like AppDomain.AssemblyResolve when reference cannot be resolved on assembly loading?

Sep 26, 2011 at 11:26 PM

You can update the host's cache explicitly by calling RegisterAsLatest, but this will probably not do what you want because the copy will hold on the dummy assembly, as befits an immutable object model.

To deal with this situation you can either eagerly preload all the assemblies that you want to read in (the reader is lazy, so this is almost always an OK thing to do), or you can get the host to probe for the assemblies.

The default host already does probing, but you may need to help it a bit by providing it with some library paths: You can pass a collection to the constructor, or you can call AddLibPath.

If your logic needs to be more sophisticated than the default host, you can customize it by overriding host methods such as ProbeAssemblyReference.