c# - 程序集.加载+依赖项

标签 c# reflection .net-assembly

我在加载 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并返回正在加载的程序集。

enter image description here

关于c# - 程序集.加载+依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59646614/

相关文章:

c# - 如何调用 Activator.CreateInstance,将方法作为构造函数参数传递?

json - Scala 2.10,它对 JSON 库和案例类验证/创建的影响

go - 从接口(interface)中获取所有字段

c# - Assembly.GetManifestResourceStream 始终返回 null

c# - 如何从窗口获取屏幕截图?

c# - EF Code First From DB 不为所有表创建实体

c# - WPF - 使用 DisplayMemberBinding 向 GridViewColumn 添加工具提示

c# - 如何从执行程序集引用库?

c# - 找不到包含 OwinStartupAttribute 错误的程序集

c# - C# 中的欧拉项目 8