为什么我的 .NET 应用程序尝试加载不相关的 DLL 文件? (调试输出中第一次出现 System.BadImageFormatException)

发布于 2024-10-17 02:52:05 字数 831 浏览 1 评论 0原文

在调试时,我注意到这里的这个 C# 应用程序出现以下情况:

它似乎尝试加载恰好与可执行文件驻留在同一目录中的所有 DLL 文件。 (即使是那些与此项目/解决方案中的任何内容完全无关的应用程序。)

该应用程序正在加载并正常工作,但是我发现调试输出很奇怪:(路径被剪断)

...
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
'my_test.exe': Loaded '....\release\mfc42u.dll', Symbols loaded (source information stripped).
'my_test.exe': Unloaded '....\release\mfc42u.dll'
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
'my_test.exe': Loaded '....\release\mpiwin32.dll', Binary was not built with debug information.
'my_test.exe': Unloaded '....\release\mpiwin32.dll'
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
...

上面的两个 DLL 与 C# 项目或它引用的任何内容。为什么可执行文件(或 VS 调试器?)尝试加载这些 DLL?

While debugging, I notice the following with this C# app I have here:

It appears to try to load all DLL files that happen to reside in the same directory as the executable. (Even ones that are completely unrelated to anything in this project/solution.)

The app is loading and working fine, however I find the debug output weird: (paths snipped)

...
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
'my_test.exe': Loaded '....\release\mfc42u.dll', Symbols loaded (source information stripped).
'my_test.exe': Unloaded '....\release\mfc42u.dll'
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
'my_test.exe': Loaded '....\release\mpiwin32.dll', Binary was not built with debug information.
'my_test.exe': Unloaded '....\release\mpiwin32.dll'
A first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll
...

The two DLLs above have absolutely nothing to do with the C# project or anything it references. Why is the executable (or the VS debugger?) trying to load these DLLs?

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

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

发布评论

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

评论(1

毁我热情 2024-10-24 02:52:05

看来这个应用程序毕竟正在主动加载这些 DLL!

我在一个我不熟悉的组件中找到了这段代码:

...
foreach (FileInfo file in dirInfo.GetFiles())
{
...
  try
  {
    Assembly ass = Assembly.LoadFrom(file.FullName);
...
  catch (Exception)
  {
    // Ignore all errors caught due to the .NET framework not being able to load an assembly.
    // Not all qualifying files in the specified directories really are valid .NET assemblies.
  }
...

0xA3 关于捕获第一次机会异常的评论让我走上了正轨!

Seems this app is actively loading these DLLs after all!

This code I found in a component I was not familiar with:

...
foreach (FileInfo file in dirInfo.GetFiles())
{
...
  try
  {
    Assembly ass = Assembly.LoadFrom(file.FullName);
...
  catch (Exception)
  {
    // Ignore all errors caught due to the .NET framework not being able to load an assembly.
    // Not all qualifying files in the specified directories really are valid .NET assemblies.
  }
...

0xA3's comment about catching the 1st chance exception got me on the right track!

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