I wrote a wrapper class which loads other assemblies using reflection. Wrapper.dll is also being loaded by a process through reflection following is the diagram to explain the scenario.
Process.exe
|___Loads__ Wrapper.dll
|_______Loads___1.dll
|___ Depends___ xyz.dll
Following is the file Structure
Root
|___A
| |__Process.exe
|___B
|__Wrapper.dll
|__C
|__1.dll
|__xyz.dll
I am using Assembly.LoadFile(@"c:\root\B\C\1.dll");
function to load the 1.dll
in Wrapper.dll
however it fails to find the dependencies as it tries to find the dependencies in A
dir, the same directory where we have process executable.
I found the solution I just changed the Assembly.LoadFile
to Assembly.LoadFrom
and its loaded perfectly fine. You can read the explanation here However following is the crust of it.
Load-From Context
The load-from context lets you load an assembly from a path that is not under the application path, and therefore is not included in probing. It enables dependencies to be located and loaded from that path, because the path information is maintained by the context. In addition, assemblies in this context can use dependencies that are loaded into the default load context.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With