I'm working with a managed EXE file that crashes immediately when run. Usually I'd expect a dialog which allows an option to launch the debugger, but no such luck in this case. Also, the program crashes too quickly for me to use attach to process in Visual Studio.
What is the solution?
You can use the stack trace available in the report details if you are using Play Console or the output of the logcat tool. If you don't have a stack trace available, you should locally reproduce the crash, either by manually testing the app or by reaching out to affected users, and reproduce it while using logcat.
Just use File/Open Project/Solution, select EXE file and Open it. Then select Debug/Start debugging. The other option is to run the EXE first and then Select Debug/Attach to process.
If you have WinDbg installed, use menu File → Open Executable to open the application directly under the debugger and automatically break immediately.
You can then use the commands under Debug (i.e., Go) to execute it normally and debug it. Also load the SOS Extensions. Not as nice as Visual Studio, but useful if you only have the EXE (and hopefully the PDB, although that's optional) and no source.
Example: This is my source code, which we assume is unavailable:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
int x = 10 - 10;
int i = 2000/x;
Application.Run(new Form1());
}
This crashes immediately, with no chance for you to attach a debugger in time. This is the WinDbg output after hitting "Run":
Removed dead ImageShack link - Freehand circles by me
After loading SOS.dll, you can use !DumpStack to see where the Exception was thrown:
Removed dead ImageShack link - No Freehand Circles, sorry!
Note that JIT or compiler optimizations may cause methods to be inlined which may make the StackTrace not 100% reliable, but for a quick overview it works.
WinDbg is a bit arcane, but once you got some basics done it's awesome and at least helps finding the root of the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With