2

I have a DLL created from native c++(say XYZ.dll). I link against that DLL in a wrapper that is C++ .NET. An object of this wrapper is used in my highest level C# code.

My question is: sometimes a function in my DLL crashes and my highest level C# code crashes with AppCrash; crash module: XYZ.dll. I am trying to figure our where it is crashing my native C++ code, but that is proving to be fruitless. I was wondering if there was a way for me to catch this crash in my C# code and move on.

4

3 回答 3

1

我认为这不是您正在寻找的答案,但至少它有助于解决问题。查看 AppDomain.UnhandledException... 您应该能够捕获并记录堆栈跟踪。

于 2013-02-08T00:59:21.363 回答
0

这是您在 Visual Studio 中调试的东西吗?如果没有,请考虑安装 Windows 调试器并在 cdb.exe 下运行您的应用程序。确保您的非托管组件具有符号 (.pdb)。如果您在调试器(即 Visual Studio 或 cdb/windbg)下运行您的应用程序并且可以重现崩溃,那么您应该能够获得堆栈跟踪。既然你暗示你拥有非托管库,我可以假设你有资源吗?如果您在 VS 中,请确保禁用 Debug Just My Code 设置。如果您在 windbg 中,那么一旦您遇到第一次机会异常,崩溃点应该会显示您的堆栈跟踪。

于 2013-02-08T02:07:04.027 回答
0

您绝对可以“赶上”这次崩溃。

在您的 C++ .NET Wrapper/Handler 中,将所有调用封装到第 3 方 DLL 中,使用 C++ try/catch 块封装所有调用。这很可能会奏效。

如果没有,请切换到使用 Windows 结构化异常处理。这将捕获本机 Win32 异常并杀死它们。你可以在这里找到 Win32 文档。

于 2013-02-08T02:23:44.660 回答