2011-02-10 27 views
1

調試時,我注意到這個C#應用程序下面我這裏有:爲什麼我的.NET應用程序試圖加載不相關的DLL文件? (在調試輸出的第一次機會System.BadImageFormatException)

這似乎是試圖加載碰巧駐留在同一目錄中的所有 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?

+1

爲什麼首先在可執行文件的目錄中有這些不需要的DLL? – DOK 2011-02-10 15:06:57

+1

@DOK - 爲什麼heck不是!?這很正常。如果一個應用程序包含多個可執行文件(並且是DLL),它們通常仍駐留在一個目錄中。 – 2011-02-10 15:09:45

回答

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執行的關於捕捉第一次機會異常的評論讓我在正確的軌道上!

相關問題