Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save randyburden/a61f9ef867ed867c3e6e270b6b702388 to your computer and use it in GitHub Desktop.
Save randyburden/a61f9ef867ed867c3e6e270b6b702388 to your computer and use it in GitHub Desktop.
How to Capture a Memory Dump When an App Crashes, particularly an app that is crashing with a stack overflow exception. Tested with .NET Core apps.

How to Capture a Memory Dump When an App Crashes

  1. Download ProcDump

    • ProcDump is a Microsoft Sysinternals command-line utility for creating memory dumps / crash dumps.
  2. Run the following command to start capturing a memory dump anytime an application crashes:

mkdir C:\MemoryDumps
procdump.exe -accepteula -ma -i C:\MemoryDumps
  1. Run the following command to stop capturing a memory dump anytime an application crashes:
procdump.exe -u

Viewing / Debugging a Memory Dump

  1. Copy the dump file to your machine
    • Zip or 7zip the file before transferring to your machine as the files are very large
    • Also, consider uploading the file via OneDrive as a faster way to copy the file to your machine
  2. In Visual Studio, be sure you have reverted your code back to the same version of the app that crashed and re-build the solution in release mode
    • Be sure to place the re-built binaries in the exact same directory on your machine so that Visual Studio can find the .pdb files
  3. In Visual Studio, open the .dmp file and click "Debug with Managed Only"
    • If a "Just My Code Warning" dialog opens, select "Disable Just My Code and Continue"
    • If a Stack Overflow error occurred, it will immediately breakpoint on the exact line that caused the Stack Overflow
    • By debugging the memory dump, you can see all active threads, double click on any thread to see the code and all variables loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment