3

Simple WPF app with a plain, empty Window in which I hook up an event handler to the Window's Activated event:

public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();
        Activated += OnWindowActivated;
    }

    private void OnWindowActivated(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }
}

When an exception is thrown in the handler and unhandled anywhere else, I expected the app to die, but it doesn't. WPF seems to be swallowing the exception somewhere and the Window pops up and keeps on running just fine.

Why?

mjl5007
  • 139
  • 1
  • 7

1 Answers1

2

This could be an issue related to running 32-bit applications on a 64-bit operating system. If that is the case then the blog post by Paul Betts should give you a good idea what is happening.

In short it looks like for 32-bit processes the .NET framework eats your exceptions due to issues with the propagation of the exception across user-mode / kernel mode boundaries. For 64-bit processes this doesn't happen, so the simplest way to test if this is indeed your problem is to rebuild your test app with for the 'Any CPU' platform and run it again. When I did that it crashed as one would expect.

Petrik
  • 1,961
  • 13
  • 23