开发者

Why is my .NET app trying to load unrelated DLL files? (First chance System.BadImageFormatException in debug output)

开发者 https://www.devze.com 2023-02-09 14:16 出处:网络
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 comple

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.BadImageFormatExcepti开发者_运维知识库on' 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?


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消