使用 C++/CLR dll 时 C# 应用程序崩溃

标签 c# c++ clr

我有 3 个应用程序,一个是输出静态库的 native C++ 应用程序,一个是此静态库的 C++/CLR 包装器,最后一个是使用 C++/CLR 包装器的 C# Windows 窗体应用程序。

当项目为空时,一切都可以正常编译和运行,但是当我在 native 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).

最佳答案

我建议看一下 Dependency WalkerFusion Log Viewer .

Dependency Walker 会告诉您是否缺少您尝试加载的 DLL。

Fusion Log Viewer 会准确告诉您 DLL 试图从何处加载。

这些通常是调试库加载问题的最简单方法,因为它们使问题变得非常明显:)

关于使用 C++/CLR dll 时 C# 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10221291/

相关文章:

C# 属性 : why does this work?

c++ - 套接字发送错误作为损坏的管道

c++ - void Print(vector<string>) 函数不打印

.net - 充分了解 .NET 版本和向后兼容性

.net - 如何在运行时检测 .NET 4.5 版当前正在运行您的代码?

c# - CLR在哪里存储一种类型实例的方法

c# - 当您在处理大数据集之前收集大量数据时,提高内存使用率的最佳方法是什么? (。网)

c# - 所有的逻辑应该写在 Controller 里面?

c# - C#Windows Form应用程序中的连接字符串错误

c++ - 变量变化值的断点?