Thought those days are gone?

I'm writing .NET code in C# for an app. During testing, my client reported a serious error -- huh, how'd you get that error? Tried replicating it in Visual Studio... no dice, then using the compiled exe, I was able to duplicate it, but the error didn't make sense... it kept throwing some nonsensical blubbering:

EventType clr20r3, P1 appnamehere.exe, P2 3.0.0.0, P3 45f6dbdb, P4 appnamehere, P5 3.0.0.0, P6 45f6dbdb, P7 18, P8 0, P9 pszqoadhx1u5zahbhohghldgiy4qixhx, P10 NIL.

Say what? Trying to find a best way to debug this... googled 'clr20r3' and came across this blog entry:

http://www.blackteaconsulting.com/journal/?p=116

Simply add the following in your project's entry point:


[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

...
}

static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
System.Diagnostics.EventLog.WriteEntry(
"AppErrorHandler", e.Message, System.Diagnostics.EventLogEntryType.Error);
}

Bingo! From looking at the Event Viewer, it was now clearly pointing to an non-existent database -- whoops, the database connection string was being inadvertently changed. Easy fix.

Thanks Wall Street guy!

Back when I was coding in VB6, there's runtime errors that didn't happen in the debug environment -- but doesn't say why or where in the application the error was occuring. Had to revert to some sleuthing and outputting strings -- painstaking work!

Now, excuse me while I see about this other problem... I'll report back.