在调试时,我注意到以下这个C#app我在这里:
似乎尝试加载所有 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?
答案 0 :(得分:2)
似乎这个应用程序毕竟正在积极加载这些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关于抓住第一次机会异常的评论让我走上正轨!