IBRA IBRA - 11 months ago 112
C# Question

Unhandled 'System.ComponentModel.Win32Exception' when using AvalonDock 2.0

I'm using AvalonDock 2.0, and when ever I open a dock container, while on debugging mode the application crash (it works fine when running without debugging). I get the below exception:

An unhandled exception of type 'System.ComponentModel.Win32Exception'
occurred in WindowsBase.dll

Additional information: The operation completed successfully

I came across this answer, which suggest to uncheck the boxes from the Exception Settings. The wired thing is that it worked the first time used it. but it doesn't any more. I've tried on other machines it doesn't work either. any suggestions to how to fix this.

Avalon code(exception thrown at line 5)

protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) {
if (msg == Win32Helper.WM_WINDOWPOSCHANGING) {
if (_internalHost_ContentRendered) {
// the below line throw the exception
Win32Helper.SetWindowPos(_internalHwndSource.Handle, Win32Helper.HWND_TOP, 0, 0, 0, 0, Win32Helper.SetWindowPosFlags.IgnoreMove | Win32Helper.SetWindowPosFlags.IgnoreResize);
return base.WndProc(hwnd, msg, wParam, lParam, ref handled);

Answer Source

Apparently there's an issue is filed, but with no response till this moment.

So as a workaround I have handled any unhandled exceptions using Application.DispatcherUnhandledException from App.xaml.cs.
Please check this answer for more details.

protected override void OnStartup(StartupEventArgs e) {
     this.DispatcherUnhandledException += AppGlobalDispatcherUnhandledException;

private void AppGlobalDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) {
     e.Handled = true;