This post has been republished via RSS; it originally appeared at: IIS Support Blog articles.
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.
Pre-requisites:
- Download DebugDiag 2.2. (Download)
- Windows 2008 and higher
NOTE: Please ensure you have sufficient disk space when using DebugDiag to 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 capture FIRST 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:
- Launch DebugDiag
- In the Rules tab select Crash and click on Next.
- In “Select Target Type” select “A specific process” and click on Next.
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 Next twice and then click on Finish to 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:
<ProcessName>__<ApplicationPool>__PID__<PIDValue>__Date__<DateValue>__Time_<TimeValue>__First chance exception<Exception_Code>.dmp
Example: w3wp__DefaultAppPool__PID__10032__Date__05_09_2012__Time_12_52_51PM__406__First chance exception 0XE0434352.dmp
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 the Exceptions… 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 - NOTE: The Exception type is case sensitive. Ensure it is entered correctly. For more details please visit the following link: http://msdn.microsoft.com/en-us/library/system.systemexception.aspx
- Click on Ok and then click on “Save & Close”.
- Click on Next twice and then click on Finish to activate the rule.
The dumps created by this rule will be in the following format:
<ProcessName>__PID__<PID>__Date__<DateValue>__Time_<TimeValue>__First Chance <ExceptionName>.dmp
Example: w3wp__PID__2364__Date__05_09_2012__Time_12_59_51PM__406__First Chance System.OutOfMemoryException.dmp
NOTE: DebugDiag help menu already has documented steps on how to gather data in most of the scenarios.