I built an application in C# with this structure:
SystemPath
— MainApplication.EXE
— API.dll
— Modules
——- Module1.dll
——- Module2.dll
The MainApplication.exe has a referency to the assembly API.dll. And it uses the assemblies Module1 and Module2 by “Assembly.Load(dllFile)”.
The files Module1.dll and Module2.dll also needs the file API.dll.
So, they need the API.dll in same path they are and i need to put the file API.dll in both directories (SystemPath and Modules).
What i want is a way to tell the modules that the file API.dll is in that folder, when i’m loading it with the Assembly.Load.
I can’t use the Global Assembly Cache and can’t change this structure.
What can i do to solve this?
In your MainApplication.exe.config file, you can add a <probing> element that specifies a semicolon-delimited list of subdirectories that will be searched when an assembly is loaded. For example:
With this in your configuration, you’ll be able to do an Assembly.Load or reference on Module1; and since your application root is still at the top-level, if Module1 does an Assembly.Load or reference to API.dll, it will get it from the top-level directory automatically.