How to generate a dump file of a .NET application

 
 
  • Gérald Barré

When an application misbehaves or hangs, generating a dump file is a valuable first step for debugging. There are several ways to do this on Windows, Linux, or Azure.

#Windows

##dotnet-dump (Windows)

The dotnet-dump global tool lets you collect and analyze dumps for .NET Core applications.

  1. Install dotnet-dump (requires .NET SDK) or download it

    Shell
    dotnet tool install --global dotnet-dump
  2. Find the process ID using the ps command

    Shell
    dotnet-dump ps
  3. Generate a dump file for a specific process ID

    Shell
    dotnet-dump collect --process-id <ProcessId>

##Windows Task Manager

  1. Press Ctrl+Shift+Esc to open the Windows Task Manager
  2. Select the "Details" tab
  3. Find the application in the list
  4. Right-click and select "Create dump file"

##SysInternals - Process Explorer

  1. Download Process Explorer: Process Explorer
  2. Open Process Explorer
  3. Right-click on the process and select the "Create Dump" menu item

##SysInternals - ProcDump (Windows)

ProcDump is a command-line utility that can generate a dump file when the application freezes or when the process consumes too much CPU.

  1. Download ProcDump: ProcDump

  2. Generate a dump file using the process name or process id

    procdump notepad
    procdump 4572

You can generate a dump file when a specific exception is thrown:

Shell
procdump64.exe -e 1 -f IOException myapp.exe
  • -e 1 generates the dump when an exception is thrown, including first-chance exceptions
  • -f IOException limits dump generation to when an IOException is thrown

##Debug Diagnostic Tool

Debug Diagnostic Tool can generate a dump file when a condition is met, such as when the application crashes or when CPU usage is high.

  1. Download Debug Diagnostic Tool v2 Update 3
  2. Start "DebugDiag 2 Collection" (available in the start menu)
  3. Configure a rule, such as when the application crashes
  4. When the condition is met, a crash dump is generated in the configured folder

##Visual Studio

If you are debugging an application, you can save a dump file directly from Visual Studio. Open the "Debug" menu and click "Save Dump As…":

##WinDbg

If you are debugging an application using WinDbg, you can use the .dump command to generate a dump file. The /ma option generates a minidump with all memory for the attached process.

.dump /ma [path]

##Windows Error Reporting

Windows Error Reporting can generate a dump file when an application crashes. See my previous post for details: Automatically create a crash dump file on error

#Linux

##dotnet-dump (Linux)

The dotnet-dump global tool lets you collect and analyze dumps for .NET Core applications.

  1. Install dotnet-dump (requires .NET SDK) or download it

    Shell
    dotnet tool install -g dotnet-dump
  2. Find the process ID using bash or PowerShell

    Shell
    dotnet-dump ps
  3. Generate a dump file for a specific process ID

    Shell
    dotnet-dump collect --type heap --process-id <ProcessId>

##SysInternals - ProcDump (Linux)

ProcDump is a command-line utility that can generate a dump file when the application freezes or when it consumes too much CPU.

  1. Download ProcDump for Linux: ProcDump For Linux

  2. Generate a dump file using the process name or process id

    procdump 4572

#Azure App Services

Azure lets you generate and analyze dump files for App Services.

  1. Select your App Service

  2. Go to "Diagnose and solve problems"

  3. Select Diagnose Tools

  4. Select "Collect Memory Dump"

  5. Click on the "Collect Memory Dump" button

  6. After a few minutes, the dump is available in the configured storage account

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

Follow me:
Enjoy this blog?