I have a .Net process which runs 24/7 which crashes once or twice per week. I have the AppDomain.CurrentDomain.UnhandledException event hooked up to log4net and the event never gets fired! The process just crashes with logging anything! This looks like a .Net runtime/CLR bug as I just get a message in the Event Log saying ".NET Runtime 2.0 Error".
I am running .Net 3.0 Sp1.
Can some please help me figure out how to fix this?
Event log message: .NET Runtime 2.0 Error Type: Error Event Id: 1000
Event log description: Faulting application appName.exe, version 0.0.0.0, stamp 4ca5d33d, faulting module mscorwks.dll, version 2.0.50727.3607, stamp 4add5446, debug? 0, fault address 0x0010724e.
A runtime error is a software or hardware problem that prevents Internet Explorer from working correctly. Runtime errors can be caused when a website uses HTML code that's incompatible with the web browser functionality.
A CLR Exception is a type of Exception made by . NET applications. The exception is encapsulated in a class derived from the System. Exception class. The Exception Code is 0xE0434352 (a.k.a. Error "CCR" in ASCII).
Most often, the . NET Runtime Error 1026 indicates that Windows is missing some files to be able to smoothly run a program. When an error code such as this appears, Windows cannot start apps.
The reports in the Unhandled Exceptions are C# exceptions that your application is not catching in a try-catch block. These do not result in a crash (the application keeps running), but may result in unexpected behavior.
I believe that a StackOverflowException would not be caught like this, as there's nowhere for the code to run. This would possibly be a good candidate for something that occurs on a reasonably regular basis - you may need to check through your code for infinite loops/recursion.
Maybe here is your solution
So, some interesting feedback, but it may also be worth mentioning that different application types may throw exceptions on different event handlers.
For a Windows Service, we should be safe handling
static void Main (string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledException;
}
For a WinForms application, we should also handle the additional unhandled event handler
static void Main (string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledException;
System.Windows.Forms.Application.ThreadException +=
Application_ThreadException;
}
For a WPF application, a dispatcher event is provided for GUI exceptions
static void Main (string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
CurrentDomain_UnhandledException;
Application.Current.DispatcherUnhandledException +=
Application_DispatcherException;
}
Also worth re-iterating, any unhandled exception typically results in program termination. Handling these events however gives us a chance to report and identify the root error.
Additional links that may help
My question regarding unhandled GUI exceptions (duplicate)
WPF global exception handler
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