tags:

views:

72

answers:

3

I installed my Windows Forms .NET 3.5 application and it installed correctly. When trying to run it the application crashes and the typical Microsoft Windows error dialog shows. You know the one that asks you to send an error report.

My question is, how can I see what actually caused the program to fail to launch?

The application runs well on my development machine, the problem is when running on another computer when installed with the Setup file I created.

Is there a way to see the 'innerException' when not running on a development machine?

+1  A: 

These are the default options you have:

  1. (If possible) change the application so that it logs errors and warnings, using e.g. log4net or the windows event log, then redistribute your app.
  2. If the first option is not possible, you'll have to check out more advanced debugging: run-time debugging on the client machine. One way is to use WinDbg with the .NET extensions (SOS) or related tools from Debugging Tools for Windows. You can set it up on a client machine without running an installer, so it should have little or no side effects (as opposed to the non-option of setting up Visual Studio). One article on this is here, where they're debugging a crash dump file. Here is another article on the topic. You'll find endless resources on this googling - the topic is not simple but I recommend you look into it.

(If you need the results now, and don't have time to dig into advanced debugging with WinDbg and related tools at the moment, I would just add some tracing into the application.)

steinar
A: 

Did you check the EventLog? If your program starts, and then begin crash. put EventLog.WriteEntry(exceptionMessage). If not, best way to see it is EventLog.

Serkan Hekimoglu
+2  A: 

Besides checking the Windows Event Viewer (from Computer Management) you could also try to build some error logging around your program. If you extend your Main() method to contain the following lines you will be able to get some further information about the cause of the program failure:

[STAThread]
static void Main()
{
    Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

    Application.Run(new Form1());
}

private static void Application_ThreadException(
        object sender, ThreadExceptionEventArgs e)
{
    //Log error here using e.Exception
}

static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    //Log error here using (Exception)e.ExceptionObjecte.Exception
}

You could for example log the error to a simple text file using a StreamWriter:

string dateStr = DateTime.Now.ToString("yyyy-MM-dd");
StreamWriter sw = File.AppendText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ErrorLog_" + dateStr + ".log"));
sw.WriteLine(exception);
Fischer