我写了一个包装器类,它使用反射加载其他程序集。 Wrapper.dll 也被进程通过反射加载,下面是解释场景的图表。
Process.exe
|___Loads__ Wrapper.dll
|_______Loads___1.dll
|___ Depends___ xyz.dll
文件结构如下
Root
|___A
| |__Process.exe
|___B
|__Wrapper.dll
|__C
|__1.dll
|__xyz.dll
我正在使用 Assembly.LoadFile(@"c:\root\B\C\1.dll");
函数加载 1.dll
Wrapper.dll
但是它找不到依赖项,因为它试图在 A
目录中找到依赖项,该目录与我们拥有进程可执行文件的目录相同。
最佳答案
我找到了解决方案,我只是将 Assembly.LoadFile
更改为 Assembly.LoadFrom
并且它的加载非常好。您可以阅读说明 here但以下是它的外壳。
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.
关于c# - Assembly.LoadFile 在可执行文件的位置查看依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36075829/