I Load a WPF MVVM Class Library with reflection. I also need an exception Handler as described here.
Since this is a Hosted WPF App, I can't use App.xaml ! It's why I implemented all needed in the class wich Load my application, as explained here, including :
Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
The problem here is that when I throw an Exception (from a backgroundworker thread BTW), It doesn't work well. In effect, if I manually throw a NullReferenceException by calling the Dispatcher.Invoke (in order to throw the exception in the UI thread), and when I get into the Current_DispatcherUnhandledException debugger, the Exception I see is not NullReferenceException, but the helly TargetInvocation Exception with a "Exception has been thrown by the target of an invocation" message.
I figured out that this Exception is maybe thrown by the invoke method, the one which call the WPF dll by reflection.
It looks like the NullReferenceException is caught by the "WPF class library caller method", before the wpf application...
It's making me go crazy !
Please help !