0

When a crash occurs in .net it seems that EventViewer doesn't contain the quite important Message part. Why is this? Am I missing something on how to get this information?

For example I am running a simple WPF application with a button that just throws an exception like this:

private void Button_Click(object sender, RoutedEventArgs e)
{
     throw new NotImplementedException("Test message for event viewer.");
}

But in EventViewer all I get is this and no sign of the message:

Application: WpfApp4.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NotImplementedException
   at WpfApp4.MainWindow.Button_Click(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
   at System.Windows.UIElement.OnMouseUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at WpfApp4.App.Main()

When this message can be quite helpful, especially in the case of Win32Exceptions.

Hopefully this is a straight forward answer but I'm struggling to find it.

  • The straightforward answer is to add proper error handling and logging in the application itself. The Event Viewer is the last chance to log something in case an application crashes. A button click shouldn't be able to crash the entire application – Panagiotis Kanavos Dec 15 '20 at 14:01
  • Check [WPF Global Exception Handler?](https://stackoverflow.com/questions/1472498/wpf-global-exception-handler) and [Globally catch exceptions in a WPF application?](https://stackoverflow.com/questions/793100/globally-catch-exceptions-in-a-wpf-application). The answers show the different ways you can catch unhandled exceptions, whether they occur in the foreground or background threads. You can use one of the popular logging libraries like NLog or Serilog to log the error in a file, the database, send an email etc – Panagiotis Kanavos Dec 15 '20 at 14:07
  • 1
    We use App Center for logging crashes, but that isn't really an answer to my question. This seems like basic information missed in Event Viewer. – james.baker Dec 15 '20 at 14:42
  • 1
    Some exceptions fire before our logging is even in place which is another reason why this information would be useful. – james.baker Dec 15 '20 at 14:43
  • Set it up earlier. Even WPF applications are a `Main` method that sets up some stuff and then starts the main form. WPF tries to hide this, but in the end that's how it works. [You can replace the autogenerated Main with your own](https://stackoverflow.com/questions/2694680/no-main-in-wpf) and wrap the code with `try/catch` – Panagiotis Kanavos Dec 15 '20 at 15:09
  • The application fault event is outside the application's control. At that point the application is *already* dead. That event is provided by the .NET runtime itself. To the runtime, the root exception is `UnhandledApplicationException` and `NotImplementedException` is the *inner* exception. There could be other exceptions, like BadImageFormat if you tried to run a x64 binary on a x86 OS – Panagiotis Kanavos Dec 15 '20 at 15:14

0 Answers0