Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
        }
like image 277
IBRA Avatar asked Jun 15 '16 12:06

IBRA


3 Answers

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.
Code:

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

private void AppGlobalDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) {
     e.Handled = true;
}
like image 68
IBRA Avatar answered Oct 19 '22 23:10

IBRA


For anyone else landing on this page, I was able to get rid of the problem with the following setting turned off:

Tools > Options > Debugging > General > Enable UI Debugging Tools for XAML

like image 35
dotNET Avatar answered Oct 19 '22 22:10

dotNET


My quick hack is that I disabled the UpdateWindowPos() in the LayoutAutoHideWindowControl class during debug config.

    internal void Show(LayoutAnchorControl anchor)
    {
        if (_model != null)
            throw new InvalidOperationException();

        _anchor = anchor;
        _model = anchor.Model as LayoutAnchorable;
        _side = (anchor.Model.Parent.Parent as LayoutAnchorSide).Side;
        _manager = _model.Root.Manager;
        CreateInternalGrid();

        _model.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_model_PropertyChanged);

        Visibility = System.Windows.Visibility.Visible;
        InvalidateMeasure();
#if !DEBUG
        UpdateWindowPos();
#endif
        Trace.WriteLine("LayoutAutoHideWindowControl.Show()");
    }

To my current experience, this results only in the disability to drag&drop of minimized dockable containers.

like image 1
Henk Avatar answered Oct 19 '22 21:10

Henk