使用Assembly.LoadFile时无法加载程序集异常

发布于 2024-10-05 16:16:22 字数 535 浏览 1 评论 0原文

这是我的场景:

我有三个项目:两个 DLL 和一个控制台应用程序,我们将它们命名为 foo.dll、bar.dll 和 console.exe。 Console.exe 使用 Assembly.LoadFile(@"c:\foo.dll") 加载 foo.dll。 Foo.dll 的项目引用了 bar.dll 并使用了一个类。 Console.exe 加载 foo.dll 正常,当 foo.dll 尝试使用 bar.dll 的类时会出现问题。我收到“无法加载程序集:”bar.dll”等等异常。

一些要点:

  • 所有项目都是强命名的
  • 宁愿不使用 GAC
  • Bar.dll 位于 c:\bar.dll 中

所以一切都在同一个中本地目录中,正在引用正确的 dll(通过项目属性,并且我使用 Reflector 来确保程序集版本正确)。如果我将 bar.dll 安装到 GAC,一切都会按预期进行

。处理 Assembly.LoadFile 调用,并跳转到第二个 DLL,但我不确定

感谢您的时间和输入。

here's my scenario:

I have three projects: two DLLs and one console application, let's name them foo.dll, bar.dll and console.exe. Console.exe loads foo.dll using Assembly.LoadFile(@"c:\foo.dll"). Foo.dll's project has a reference to bar.dll and makes use of a class. Console.exe loads foo.dll fine, the problem occurs when foo.dll tries to use bar.dll's class. I get a "could not load assembly: "bar.dll" blah blah exception.

Some points:

  • All projects are strong named
  • Would prefer to not use the GAC
  • Bar.dll is in c:\bar.dll

So everything is in the same local directory, the correct dlls are being referenced (via project properties, and I've used Reflector to make sure the assembly versions are correct). If I install bar.dll to the GAC everything works as expected.

I think it has something to do with the Assembly.LoadFile call, and making a hop to the second DLL, but I'm not sure.

Thanks for your time and input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

翻了热茶 2024-10-12 16:16:22

Assembly.LoadFile() 只应在非常特殊的情况下使用。该程序集没有加载上下文,这就是找不到 bar.dll 的原因。唯一真正的用例是转储程序集元数据的工具和程序。

使用 Load 或 LoadFrom()。解决 fuslogvw.exe 问题

Assembly.LoadFile() should only ever be used in very special circumstances. The assembly doesn't have a loading context, that's why bar.dll cannot be found. The only real use case is tooling, programs that dump assembly metadata.

Use Load or LoadFrom(). Troubleshoot problems with fuslogvw.exe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文