Search code examples
c#.nettermination

Unknown Hard Error message is shown when application exits using a call to Environment.FailFast


We have a C# application that hooks up to AppDomain.UnhandlerExceptions and listens to any unhandled exceptions in the application. Once there is a unhandled exception, it shows an error message to the user and kills the application via a call to Environment.FailFast.

The issue is that on some machine this causes a "Unknown Hard Error" message to be shown to the user and the application does not exit till we click "Ok".

The OS is Windows 7 x64 with .NET 4 application.


Solution

  • We contacted Microsoft and it turned out that it was because Windows Error Reporting Service was disabled on the Windows machine.

    The call flow is like this:

    1. Application terminates it self by calling Environment.FailFast.
    2. CLR checks if any debugger has registered to handle the exception. Incase a debugger is registered, the exception is handled by the debugger.
    3. Incase there are no debuggers, CLR tries to pass the exception on to the OS. It tries to start the Windows Error Reporting Service and pass the exception to it.
    4. Incase it fails to start Windows Error Reporting Service, it queues an Unknown Hard Error in the kernel and the Unknown Hard Error message is shown to the user.