Question Regarding Assembly.LoadFile when loading assemblies that reference other assemblies

LycaonX

New member
Joined
Aug 11, 2010
Messages
3
Programming Experience
10+
Okay, for brevity's sake I'm calling my host application, which uses a plugin architecture, A. The assembly that it is loading will be called B, and the assembly that B references is called C. C is not an assembly installed in the GAC, nor do I want do to this, because B, and if present, its referenced C, is an arbitrary assembly coded by end users that I probably do not want floating around the GAC.

Basically A exports an Interface that plugins implement in order to be loaded. I already have code that loads their plugin assembly and extracts out any class that implements my interface, there is no problem there.

The issue that comes up is, if they write assembly B, and then that assembly references a second custom plugin assembly, C, then Assembly.LoadFile("B.dll") works fine, BUT when I try to B.GetTypes, I get a ReferenceTypeLoaderException that basically says "Could not load file or assembly C"

Assembly B and assembly C reside in the same folder.

I have tried setting application A's CurrentDirectory to the folder I'm loading the plugins from. Probably a stupid way to go about it, but I tried and that did not work. I checked the Assembly class for a property that let me specify a search path. No dice.

I have also tried extra stupid things like copying assembly B to application A's base directory, loading copied assembly B, getting all of its referenced assemblies via GetReferencedAssemblies, then searched B's orginal directory for all of the referenced assemblies, and if said assembly exists, then I copied that to application A's base folder. Messy as hell, but it didn't work. Basically I did it that way because GetReferenedAssemblies usually contains assemblies that are in the GAC and there's no need to copy them.

EDIT: The above DOES work but I really would not rather have dozens of assemblies littering my app's base folder.

I'm at a loss here. If I have another plugin, called D, that is self contained and does not reference anything 'extra', it loads fine. This is okay in most cases, but there are (and have been) cases where that third assembly, C, is required no matter what. Any suggestions?

More Info / EDIT2: I am aware that placing the plugins in a subfolder in the app directory works fine. The specific code in question is a builtin miniIDE for editing dynamically compiled assemblies, and they may or may not be compiled directly inside the application's plugin folder. If they are not, I still need to be able to read the assembly and its referenced assemblies to provide intellisense information. We're again back to the basic question of: Is there a way to provide additional search paths when loading an assembly via Reflection?
 
Last edited:
<- facepalms

Thank you very much. I wish the intellisense comments for both of those methods were as clear as that website.
 
Back
Top