This article is contributed. See the original author and article here.

Debug Diag involves various methods of dump collection methods that can be incorporated. In this blog we would be dealing with one such method that helps to capture crash dumps on particular exception only when it contains a specific function in its call stack.


 


When can you use this type of data collection?


 


You can use this method to capture the dumps if you are facing the below challenges:



  • Your application pool recycles very frequently making it difficult to monitor the process ID for procdump command to run

  • The exception being targeted can occur in other scenarios as well, hence generating a lot of false positive dumps

  • We know call stack of the exception or a specific function call where the exception comes from


 


Steps to capture dumps for an exception occurring from specific method :



  1. Download the latest Debug Diagnostic Tool v2 Update 3 from https://www.microsoft.com/en-us/download/details.aspx?id=58210

  2. Open the Debug diag collection

  3. Once you open this , you will automatically be prompted with Select Rule Type wizard, if not select Add Rule from the bottom pane

  4. Select Crash and chose A specific IIS web application pool

  5. Chose the required application pool and click Next

  6. Click on Exceptions and got to Add Exception in the following prompt that appears

  7. Chose the type of exception your require and select Custom from Action Type

  8. Once you chose Custom you will be presented with a page to add your script

  9. Add the following script :

    If Instr(UCASE(Debugger.Execute("!clrstack")),ucase("Your function here")) > 0 Then
    
                                                          CreateDump "Exception",false
    
    End If


  10. Alternatively if you want to capture a dump for an exception that might be coming from two different methods you can use this:

    If Instr(UCASE(Debugger.Execute("!clrstack")),ucase("function 1")) > 0 Then
    
                                                           CreateDump "Exception",false
    
    ElseIf  Instr(UCASE(Debugger.Execute("!clrstack")),ucase("function2 ")) > 0 Then
    
                                                          CreateDump "Exception",false
    
    End If 


  11. Set the Action Limit to number of dumps to be captured and hit OK

  12. Click Save and Close and Next in the following command prompt that appears

  13. Alter the Rule name and location in next prompt if required

  14. Chose Activate the rule now and Finish


 


For example, Let’s assume that we are getting the exception “System.Threading.ThreadAbortException” from method “EchoBot.dll!Microsoft.BotBuilderSamples.Controllers.BotController.PostAsync() Line 33”. In this scenario we will follow the below steps :


 



  1. Complete the steps from step 1 to step 6 as written above

  2. Chose the CLR Exception from the list of exceptions presented to you

  3. In Exception Type Equals column add :  System.Threading.ThreadAbortException

  4. In Action Type , chose Custom from drop down menu

  5. In the Provide DebugDiag Script Commands For Custom Actions prompt that appears paste the following script :

    If Instr(UCASE(Debugger.Execute("!clrstack")),ucase("Microsoft.BotBuilderSamples.Controllers.BotController.PostAsync")) > 0 Then
    
                                                          CreateDump "Exception",false
    
    End If


  6. Follow the steps from 11 to 14 above to complete the configuration


 


This rule creates the dump on System.Threading.ThreadAbortException that occurs from Microsoft.BotBuilderSamples.Controllers.BotController.PostAsync.


 


More information:

The script indicates debug diag to capture the dump when it hits the exception you selected and involves the function call ( you mentioned in script ) in it’s call stack.


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.