2012-04-19 153 views
0

當我有3個應用程序的一個是一個本地C++應用程序,它輸出一個靜態庫中,一個是用於該靜態庫中的C++/CLR包裝和最後一個C#窗口形成應用程序,使用C++的/ CLR包裝。C#應用崩潰使用C++/CLR DLL

當項目是空的一切編譯和運行正常,但當我在本地C++應用程序添加一些代碼我的課,我得到的C#WinForms應用程序崩潰。

以下是錯誤消息:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in  
WindowsFormsApplication1.exe 
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in 
WindowsFormsApplication1.exe 

Additional information: Could not load file or assembly 'stenCLR.dll' or one of its 
dependencies. The specified module could not be found. 

我相信stenCLR.dll是正確的文件夾。

下面是從Visual Studio完整的錯誤日誌:

'WindowsFormsApplication1.exe': Loaded 'E:\ST Projects\sten_svn\trunk\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe', No native symbols in symbol file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\mscoree.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\msvcr110_clr0400.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\db19194dcf61188e0e1bb9b6b2dba362\mscorlib.ni.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll' 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Program Files (x86)\Common Files\microsoft shared\ink\tiptsf.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\version.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe' (Managed (v4.0.30319)): Loaded 'E:\ST Projects\sten_svn\trunk\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe', Symbols loaded. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System\529187426262f016595cb4b92bc83241\System.ni.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\6007a55278ac4372ab91f08ead86756e\System.Drawing.ni.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\1242e9bc90b42762b6c7f2a5052a2280\System.Windows.Forms.ni.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll' 
'WindowsFormsApplication1.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll' 
'WindowsFormsApplication1.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll' 
'WindowsFormsApplication1.exe': Loaded 'ImageAtBase0x50d00000', Loading disabled by Include/Exclude setting. 
'WindowsFormsApplication1.exe': Unloaded 'ImageAtBase0x50d00000' 
'WindowsFormsApplication1.exe': Loaded 'ImageAtBase0x519b0000', Loading disabled by Include/Exclude setting. 
'WindowsFormsApplication1.exe': Loaded 'ImageAtBase0x7f0000', Loading disabled by Include/Exclude setting. 
'WindowsFormsApplication1.exe': Unloaded 'ImageAtBase0x519b0000' 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\cryptsp.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\rsaenh.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\RpcRtRemote.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'E:\ST Projects\sten_svn\trunk\WindowsFormsApplication1\bin\Debug\stenCLR.dll', Symbols loaded. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\msvcr110d.dll', Symbols loaded. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\msvcp110d.dll', Symbols loaded. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\d3d11.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\dxgi.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file. 
'WindowsFormsApplication1.exe': Unloaded 'E:\ST Projects\sten_svn\trunk\WindowsFormsApplication1\bin\Debug\stenCLR.dll' 
'WindowsFormsApplication1.exe': Unloaded 'C:\Windows\SysWOW64\d3d11.dll' 
'WindowsFormsApplication1.exe': Unloaded 'C:\Windows\SysWOW64\dxgi.dll' 
'WindowsFormsApplication1.exe': Unloaded 'C:\Windows\SysWOW64\dwmapi.dll' 
'WindowsFormsApplication1.exe': Unloaded 'C:\Windows\SysWOW64\msvcp110d.dll' 
'WindowsFormsApplication1.exe': Unloaded 'C:\Windows\SysWOW64\msvcr110d.dll' 
First-chance exception at 0x753eb9bc in WindowsFormsApplication1.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x003bcce4. 
First-chance exception at 0x753eb9bc in WindowsFormsApplication1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000. 
First-chance exception at 0x753eb9bc in WindowsFormsApplication1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000. 
First-chance exception at 0x753eb9bc in WindowsFormsApplication1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000. 
First-chance exception at 0x753eb9bc in WindowsFormsApplication1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000. 
First-chance exception at 0x753eb9bc in WindowsFormsApplication1.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000. 
A first chance exception of type 'System.IO.FileNotFoundException' occurred in WindowsFormsApplication1.exe 
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in WindowsFormsApplication1.exe 

Additional information: Could not load file or assembly 'stenCLR.dll' or one of its dependencies. The specified module could not be found. 

The program '[2000] WindowsFormsApplication1.exe: Native' has exited with code 0 (0x0). 
The program '[2000] WindowsFormsApplication1.exe: Managed (v4.0.30319)' has exited with code 0 (0x0). 

回答

3

我建議考慮看看Dependency WalkerFusion Log Viewer

的Dependency Walker會告訴你,如果有任何DLL的,你要加載的一個缺失。

融合日誌查看器會告訴你究竟DLL試圖從哪裏加載。

這些通常是調試庫加載的問題,因爲他們使這一問題變得極其明顯:)

+0

當我在dependency walker中打開exe文件時,我在底部看到此消息: 警告:至少找不到一個延遲加載依賴項模塊。 警告:由於延遲加載相關模塊中缺少導出功能,因此至少有一個模塊具有未解析的導入。 在列表視圖中,2個文件被突出顯示: GPSVC.DLL和IESHIMS.DLL,我甚至不知道它們是什麼。 也嘗試運行Fusion Log Viewer,但它不顯示任何綁定失敗。 – 2012-04-19 03:42:55

+0

@BarisUsakli只需谷歌他們。 IESHIMS.dll與IE(Program Files \ Internet Explorer)相關,GPSVC.DLL與組策略(%SYSTEMROOT%\ WINDOWS \ System32 \)相關。通常這些安裝在IE/Windows中,但是您可以通過查找它們並將它們與DLL一起復制並再次嘗試來查看是否是您的問題。 – 2012-04-19 03:50:45

+0

我會盡力,同時我能夠重現/解決問題,但它沒有任何意義。如果我把: std :: unique_ptr _d3dObject;如果我將其替換爲 std :: shared_ptr _d3dObject,則c#應用程序崩潰;它運行良好。 D3DObject的頭文件包含在該文件中。 (facepalm) – 2012-04-19 03:54:47

1

一種可能性是,你有一個64位的機器,編爲「任何CPU」位或64位的C#應用​​程序的最簡單方法而C++本地庫或C++/CLI是32位。 在這種情況下,系統會查找64位庫。

確保所有應用程序都是爲相同架構x86或x64構建的。

+0

是的,他們都是x86。 – 2012-04-19 13:45:00