Compartilhar via


Catch Exceptions on x64

Hello All,

Just recently I came across an incident on which a customer saw the following exception in his Application Event Log:

Event Type: Warning
Event Source: ASP.NET 2.0.50727.0
Event Category: Web Event
Event ID: 1309
Description:
Event code: 3005
Event message: An unhandled exception has occurred.

Exception information:
Exception type: IndexOutOfRangeException
Exception message: Index was outside the bounds of the array.
……

I wondered how I would take memory dump for an exception on Windows Server 2003 x64 server. We cannot use Debug Diagnostics Tools on x64 bit machines.

I then came across a blog by Tess Are you aware that you have thrown over 40,000 exceptions in the last 3 hours? and this post gave me the answer. Though running the exact TrackCLR.cfg did not capture the exception dump. Here is the code that did the trick for me.

 <ADPlus>
    <Settings>
        <RunMode> CRASH </RunMode>
        <OutputDir> c:\dumps </OutputDir>
        <Option> Quiet </Option>
        <ProcessName> w3wp.exe </ProcessName>
    </Settings>
    <!-- defines a set of commands to execute before the sxe and bp commands -->
    <PreCommands>
        <cmd>r $t1 = 0</cmd>
        <cmd>r $t2 = 0</cmd>
        <cmd>!load sos</cmd>
        <cmd>!threads</cmd>
    </PreCommands>
    <Exceptions>
        <Config>
            <Code>AllExceptions</Code>
            <Actions1>Log</Actions1>
            <Actions2>Void</Actions2>
        </Config>
        <Config>
            <Code>CLR</Code>
            <Actions1>Log</Actions1>
            <CustomActions1>!soe System.IndexOutOfRangeException 1;.if(@$t1==1) {.echo 'System.IndexOutOfRangeException occurred';.dump /ma c:\dumps\ExceptionDump.dmp;gn} .else {.echo 'some other exception occurred';!clrstack;gn}</CustomActions1>
        </Config>
    </Exceptions>
</ADPlus>

Perform the following steps:

Install Debugging Tools for Windows 64-bit Version from here.
Open command prompt and go to C:\Program Files\Debugging Tools for Windows or to the path where you installed Debugging Tools for Windows x64-bit.
Save the above code as TrackCLR.cfg.
Type the command: cscript.exe adplus.vbs –c TrackCLR.cfg.
Adplus will create ExceptionDump.dmp in C:\dumps folder. 

Keep in touch..