Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get stack trace for C# app crashing on non-dev machine

I have installed a C# windows forms app on a client machine which does not have Visual Studio installed.

When the application is run, it immediately crashes with a dialog which says

ProgramX has stopped working. A problem caused the program to stop working correctly. Please close the program."

The only button on the dialog is "close the program".

I would like to see the exception message and stack trace so that I can diagnose the issue.

I have tried installing the .Net SDK, which comes with "windbg". I have run the program in windbg, and managed to get it to say "CLR exception". However, I cannot get windbg to print the exception message or stack trace. It will not load SOS or PSSCOR2, because of DLL loading messages, even after lots of fiddling. There must be an easier way!

(If your answer involves windbg, please include detailed step by step instructions as I have tried and failed at this approach.)

The application is a .Net 3.5 app. The machine has .Net 3.5 and .Net 4 installed. There is nothing in the event log (that I can find).

like image 568
Rich Avatar asked Jan 16 '23 08:01

Rich


2 Answers

If you do NOT have access to source code then you have a problem. Exceptions should finish in windows events. Maybe exception is being suppressed.

If you DO have access to source code you can surround starting code with TRY\CATCH and in CATCH and print exception info to a file:

  • ex.message
  • ex.InnerException.Message
  • ex.StackTrace

Code

        try
        {
            //Your code
        }
        catch (Exception ex)
        {
            //Log info to a file in same directory
        }
like image 145
Oscar Foley Avatar answered Feb 01 '23 03:02

Oscar Foley


  • You can catch unhandled exceptions in one place in your code by adding a handler to the following event. You can then log or perform some other action.

    AppDomain.UnhandledException

  • You can generate a crash dump from Task Manager (right-click on an entry in the Processes tab and select Create Dump File) and load it with WinDbg. Running the !pe command should display the exception. You will need the PDB files from your build and the correct version of the SOS DLL from the machine that crashed.

like image 35
Thomas Bratt Avatar answered Feb 01 '23 05:02

Thomas Bratt