Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Runtime Error causes process to crash! But there's no unhandled exception - Why? CLR bug?

Tags:

c#

.net

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.

like image 315
arkina Avatar asked Feb 16 '11 15:02

arkina


People also ask

What causes a .NET runtime error?

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.

What is CLR exception?

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).

What is .NET runtime error?

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.

Is unhandled exception a crash?

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.


3 Answers

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.

like image 56
Paddy Avatar answered Sep 28 '22 14:09

Paddy


Maybe here is your solution

like image 32
Stecya Avatar answered Sep 28 '22 13:09

Stecya


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

like image 41
johnny g Avatar answered Sep 28 '22 15:09

johnny g