Tip: Automatically create a crash dump file on error

  • Tips
  • Windows

Crash dumps are very useful to debug an application. Recently, I worked on a Visual Studio extension we use in my company. It's very easy to develop such kind of application. However, there are lots of reasons for your extension to crash. Of course you can add lots of try/catch, but you'll for sure forget the good one, so VS will crash. When it's happening, you would like to be able to attach a debugger and see the exception and the stack trace. Instead of attaching a debugger, you can automatically generate a crash dump that you can use to debug the application later.

In Windows, you can configure Windows Error Reporting (WER) to generate a dump when an application crashes.

  1. Open regedit.exe
  2. Open the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
  3. Set the value DumpFolder (REG_EXPAND_SZ) to the directory you want the dump to be created
  4. Optionally, you can prevent WER to keep lots of crash dumps by setting DumpCount (DWORD) to a low number

Maybe you prefer set the configuration using PowerShell:

New-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting" -Name "LocalDumps"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpFolder" -Value "%LOCALAPPDATA%\CrashDumps" -PropertyType "ExpandString"
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" -Name "DumpCount" -Value 10 -PropertyType DWord

You can also configure WER per application. So, if you want to generate a full dump only for one application, you can create a key for your application under LocalDumps with the configuration you want. If you application is devenv.exe the key name is devenv.exe. This is very simple!

WER configuration

When you application crash, you can go to %LOCALAPPDATA%\CrashDumps:

WER configuration

Find the latest dump and open it using Visual Studio to start debugging the application. By default, it shows system information, the exception that crahes the application, and the list of modules. You can use the action section on the right to start the debugger and find more information about the exception.

Debug crash dump in Visual Studio

Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/bb787181.aspx

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee


George -

Thanks for all the great info, this is very useful.

I set up my machine this way but found that the dump is not created automatically. It will only be created once the crash notification popup it closed. I'm trying to use this with automated tests so there won't be anyone around to close the popup. Is there any way to circumvent this?

Gérald Barré -

@George Applications that do their own custom crash reporting, including .NET applications, are not supported by this feature.

That's being said, for automated testing you should disable Windows Error Reporting (WER) completely:

  • PowerShell: Disable-WindowsErrorReporting (documentation)

  • Using the registry (copy the following content in a .reg file and run it):

    Windows Registry Editor Version 5.00
    [HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting]