Assembly.Load + 依赖项

Assembly.Load + Dependencies

我在加载 DLL 及其引用时遇到问题。场景是这样的:

我有一个 C# 库项目(我们称之为 "A"),它引用了另一个 C# 库项目(我们称之为 "B")。这两个项目的 Dll 都存储在 Azure Blob 存储上,但这在现实中是无关紧要的。

作为我项目的一部分,我正在使用 XslCompiledTransform.Transform。使用 Assembly.Load 加载 dll A 后,我再次使用 Assembly.Load.

加载 dll B

问题是,在执行 Transform 方法后,我一直收到一个错误,即 dll B 找不到 ,即使我调用 AppDomain.CurrentDomain.GetAssemblies();

请注意,如果我从 A 中删除 B 的依赖项,则一切正常,因此我们可以确保仅使用 dll A 的 Transform 正常工作。

FileNotFoundException: Could not load file or assembly 'xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

还有一点,如果我将 dll B 添加到项目的 Bin 文件夹中,那么它就可以工作,但是当然,我不能这样做,我这样做只是为了证明它可以工作。

正如@Luaan 所解释的,我不得不使用 AppDomain.AssemblyResolve 和 return 正在加载的程序集。