exception code: 0xc00000fd. Debugging a StackOverflowException

If your website is causing a StackOverflowException, you'll see errors in the application and system event logs. Examples:

The requested operation caused a stack overflow.
Event Name: APPCRASH
Problem signature:
P1: w3wp.exe
... lines removed
P4: ntdll.dll
... lines removed
P7: c00000fd
Faulting application name: w3wp.exe, version: 7.5.7601.17514
Faulting module name: ntdll.dll, version: 6.1.7601.17725
Exception code: 0xc00000fd
... lines removed
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
A process serving application pool 'www.your-awesome-site.com' suffered a fatal communication error with the Windows Process Activation Service. The process id was '6284'. The data field contains the error number.

A StackOverflowException typically occurs in the case of unbounded recursion. Your try-catch blocks will NOT catch these. Instead, the corresponding process is terminated. This could result in the application pool shutting down and visitors to your site encountering a 503 error.

You'll need two programs in order to track down the culprit.

Debug Diagnostic Tool (DebugDiag 1.2)

DebugDiag can be configured to generate a crash dump when the StackOverflowException occurs. Download at http://www.microsoft.com/en-us/download/details.aspx?id=26798.

  1. Open DebugDiag and click Add Rule.
  2. "Crash" should already be selected. Click Next.
  3. Choose "A specific IIS web application pool" and click Next.
  4. Select the application pool and click Next.
  5. You should be on the Advanced Configuration Window. Click Exceptions under Advanced Settings.
  6. Click Add Exception and choose Stack Overflow, with an Action Type of Full Userdump

    DebugDiag Configuration
  7. Click OK and save and close out.

Next time a StackOverflowException occurs, you'll have a crash dump. The steps cover how to interpret the dump file.

Debugging Tools for Windows (MSDN entry)

Debugging tools for Windows is part of the Windows SDK and can be downloaded at  http://msdn.microsoft.com/en-US/windows/hardware/gg463009/.

  1. To use WinDbg, you'll need to get the symbols files. Download the symbol files and put them in a local folder.
  2. Open up WinDbg. On the File menu, click Symbol File Path.
  3. In the Symbol path box, the documentation says to type the following command: SRV*your local folder for symbols*http://msdl.microsoft.com/download/symbols, however I just put in the local folder for the symbols and it worked fine.
  4. Exit out and open WinDbg again, and Open Crash Dump and locate the dump file that was created by DebugDiag.
  5. In the command line, type .loadby sos clr
  6. Now type !CLRStack

It may take a few seconds to finish writing out... but the root of your problem should be apparent. Now go fix it!