Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create minidump of a .NET process when a certain first chance exception occurs

My application throws InvalidCastException in the QA environment, something I cannot reproduce in development.

I wish to obtain the minidump at the exception moment. I know about adplus, but I am not sure how to use it so that it creates the minidump when InvalidCastException is thrown. Apparently, it does not distinguish one .NET exception from another. May be I am wrong and there is a way. Or, there is another tool to do it. Preferably free one.

Anyway, can anyone advice how to handle this issue?

Thanks.

UPDATE

  1. The build is a Debug build in both QA and dev. However, QA runs complex scenarios made possible in the lab, which devs cannot reproduce. Hence I need an ability to make dump when running in QA.
  2. I can modify the code and create minidump from code. However, I wish for a more flexible solution, the one not requiring to modify the code every time an issue like this occurs.

UPDATE 2

Actually, I have "stolen" the minidump generation code from John robbins SuperAssert.Net Again, this is code for generating minidump from certain concrete point, whereas I need a more flexible approach in the style of adplus. John Robbins' approach is create a cdb script and then invoke the cdb debugger with that script to make it attach to the process and create the dump. It does not utilize the MiniDumpWriteDump API.

like image 574
mark Avatar asked Jun 09 '10 11:06

mark


3 Answers

The easiest way is to let it bubble up all the way out of the app, let the user report it to Microsoft, and enroll in Windows Error Reporting.

Alternatively, you can capture it by hand by using John Robbins' SUPERASSERT .NET (or a subset of his code).

UPDATE (for non-code solution): Take a look at Systems Internals' ProcDump.

like image 127
Stephen Cleary Avatar answered Sep 21 '22 02:09

Stephen Cleary


Do you probably want to use MiniDumpWriteDump API in your C# application? Look at http://blog.kalmbach-software.de/2008/12/13/writing-minidumps-in-c/ for a code example or search in Internat for MiniDumpWriteDump and C#.

If you use Visual Studio 2010 you can load minidump direct in Visual Studio (see http://msdn.microsoft.com/en-us/library/d5zhxt22(v=VS.100).aspx)

like image 38
Oleg Avatar answered Sep 23 '22 02:09

Oleg


It's possible, you have to .load sos.dll in your ADPlus script. This blog post shows you how.

Beware of the questionable joys of debugging managed code from a minidump. If you are running into hard-to-diagnose exceptions while it is still in QA, you'll run into it again when it goes into production. With dragons breathing fire added then. Take care of good unhandled exception logging by writing an event handler for AppDomain.UnhandledException. Logging e.ExceptionObject.ToString() gives a wealth of information.

like image 22
Hans Passant Avatar answered Sep 21 '22 02:09

Hans Passant