.Net 应用程序中带有 STATUS_STACK_OVERFLOW 的应用程序崩溃是否意味着堆栈溢出发生在本机代码中?

Does an appcrash with a STATUS_STACK_OVERFLOW in a .Net application mean the stack overflow occured in native code?

我在 ntdll.dll.

中遇到执行代码为 c00000fd (STATUS_STACK_OVERFLOW) 的应用程序崩溃

这是否意味着在我的托管代码之外的本机代码中某处存在堆栈溢出?因为对于托管代码,我们有 System.WhosebugException。但是在我的例子中有 none,没有可以提供线索的堆栈跟踪。

你再也抓不到System.WhosebugException

Starting with .Net 2.0 they can only be caught in the following circumstances.

  • The CLR is being run in a hosted environment where the host specifically allows for Whosebug exceptions to be handled
  • The Whosebug exception is thrown by user code and not due to an actual stack overflow situation (Reference)

虽然错误说它发生在 ntdll.dll 中,但很可能是由您的代码引起的。

我的第一步是在生产中添加或打开最高级别的调试日志记录,这样您就可以尝试缩小它发生的位置和情况。

其次,我将开始调试(附加调试器)并仔细检查该方法 class,直到找到它。很可能是由于某种递归,这是我开始寻找的第一个地方。


其他资源和参考资料

C# catch a stack overflow exception

How to find the source of a WhosebugException in my application

How to debug System.WhosebugException without link to source code?

How do I prevent and/or handle a WhosebugException?

How to debug a Whosebugexception in .NET

Troubleshooting Exceptions: System.WhosebugException

WhosebugException Class

In the .NET Framework 1.0 and 1.1, you could catch a WhosebugException object (for example, to recover from unbounded recursion). Starting with the .NET Framework 2.0, you can’t catch a WhosebugException object with a try/catch block, and the corresponding process is terminated by default. Consequently, you should write your code to detect and prevent a stack overflow. For example, if your app depends on recursion, use a counter or a state condition to terminate the recursive loop.