Capturing memory dumps is a common troubleshooting methodology. DebugDiag is usually an ideal choice for collecting memory dumps. I will be discussing on how we can gather memory dumps using DebugDiag when an application hosted on IIS encounters a First-chance exception.
Before we proceed, lets understand what a First-chance exception is. From here:
What is a First-Chance Exception?
When an exception is first thrown, whether from the application itself or from dependent or platform code, it is known a “first chance” exception – the debugger is given the first chance of inspecting the exception prior to the application handling it (or not). All exceptions start as first chance exceptions, and the debugger gets notified each time an exception is thrown.
NOTE: Please ensure you have sufficient disk space when using DebugDiagto capture memory dump. The dump files are as big as the process. So if you have a process consuming 600 MB, the dump file would around ~600 MB. If there are many files created then you are running at the risk of crashing the server due to insufficient disk space.
There are 2 ways to captureFIRST CHANCE EXCEPTION memory dumps of a process.
Method 1: Generate a dump for all First Chance Exception or
Method 2: Target a specific First chance exception (Recommended)
Method 1: Generate a dump for all First Chance Exception
This is the easiest way to capture a dump for any exception that is raised within the process. However, this is not the recommended way to gather data as this captures any exception and in some scenarios where there are too many exceptions can lead to generation of too many memory dumps which can have negative impact on the machine and the disk space. Below are the steps to configure the same:
In theRulestab selectCrashand click onNext.
In “Select Target Type”select “A specific process” and click onNext.
Note: If the target is a web application hosted on IIS then, choose either “All IIS/COM+ related processes” or “A specific IIS web application pool”.
In “Select Target” select the target process and click on Next.
In “Advanced Configuration (Optional)” under “Unconfigured First Chance Exceptions” set the following: Action type for unconfigured first chance exceptions:Full Userdump Action Limit for unconfigured first chance exceptions: 10
Click on Nexttwice and then click on Finishto activate the rule.
This will generate a dump for any unconfigured exception that may occur inside the target process. The file name will be in the following format:
Method 2: Target a specific First Chance Exception (Recommended)
Refer the instructions in Method 1 until step 5. After that refer the below instructions. For the purpose of this post, we are targeting OutOfMemoryException.
In “Advanced Configuration (Optional)” click on theExceptions…button.
In “First chance Exception Configuration” click on “Add Exception…”
In “Configure Exception” select the Exception code from the LHS and since we are targeting OOM, specify the details as shown below: .NET Exception Type:System.OutOfMemoryException Action Type:Full Userdump Action Limit:3