CCI and AppDomain

Jun 1, 2009 at 5:23 AM
Edited Jun 1, 2009 at 5:23 AM


I have two Assemblies A and B. I am adding one type say Type1 from A to B. Now type1 refers to some other type say TypeRef which is in third Assembly C.
Now before writing the mutated assembly B using PEWriter I will have to explicitly add the reference of Assembly C into B.

In this case I wanted to know that if Assembly to be referred (here Assembly C) is loaded into the Current AppDomain then is there any way by which I will not have to explicitly add the reference to it and it will be automatically picked up?


Thanx in advance.

Jun 1, 2009 at 6:02 AM

PEWriter will only write out the assembly references explicitly listed in the AssemblyReferences property of assembly B. If you want to "automagically" discover this list, the most obvious way to do it is to preprocess assembly B just before you submit it to PEWriter. More specifically, if you run a visitor over assembly B and collect all of the assembly references into a hash table (simply by overriding the Visit(IAssemblyReference) method of the base traverser), you can just run construct a new list of assembly references using the keys of the hash table.

The fact that assembly C is loaded into the Current AppDomain is not particularly relevant to this scenario, if I understand it. It could matter if you wanted to resolve the reference to assembly C (for example by resolving a reference to a type from C). In that case, assembly C would have to be loaded in the host for the resolution to succeed. The resolution process does have a call back to the host, which could then run through the assemblies in the current AppDomain to find the location of assembly C. CCI makes no use of System.Reflection, so this is about the only reason you may want to use any System.Reflection functionality.