使用AvalonDock 2.0时出现未处理的“System.ComponentModel.Win32Exception”错误

7
我正在使用AvalonDock 2.0,每当我打开一个停靠容器时,在调试模式下应用程序崩溃(运行时没有问题)。我收到以下异常:

未处理的类型为'System.ComponentModel.Win32Exception'的异常发生在WindowsBase.dll中

其他信息:操作成功完成

我看到了这个答案,建议取消异常设置中的复选框。奇怪的是,它第一次使用时有效。但现在不再有效。我已经尝试在其他机器上,但仍然无效。有什么建议如何解决这个问题吗?
Avalon代码(异常出现在第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);
        }

这只是图书馆设计师愚蠢的编码。他们正在抛出一个带有表示成功的错误代码(可能是ERROR_SUCCESS)的Win32Exception。异常构造函数将该错误代码转换为消息,即“操作已成功完成”-即未发生错误。向库的维护者提交错误报告。 - Cody Gray
@CodyGray 是的,没错,但是有没有办法从应用程序端停止捕获异常呢?就像我在问题中引用的答案一样。这个解决方案一开始是有效的,但现在不再有效了。我也搞不清为什么。 - IBRA
1
我假设你正在运行64位的Windows版本?这就解释了为什么当异常在窗口过程中抛出时会被悄悄地吞噬。这个库中的设计决策越来越糟糕了。我甚至无法弄清楚为什么那一行代码会抛出异常。唯一有意义的是,他们错误地注释了SetWindowPos的P/Invoke签名,并将PreserveSig设置为false。这导致返回一个表示成功的返回值与返回一个表示失败的返回值混淆。我提到过你应该向库的维护者提交错误报告吗? - Cody Gray
@CodyGray 你确实提到了它 ;) 感谢你的帮助,谢谢。 - IBRA
@IBRA:我确认你的观察结果。每次都在第31次调用时抛出异常。很奇怪。 - kmote
显示剩余4条评论
3个回答

3

显然已经提交了一个问题,但至今没有得到回应。

因此,我使用了App.xaml.cs中的Application.DispatcherUnhandledException处理任何未处理的异常。
请查看此答案以获取更多详情。
代码:

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;
}

当在Windows 10上以Debug或Release模式从VS2015中运行时,应用程序在关闭时不会终止,但使用此解决方案后,需要单击调试停止按钮才能最终终止应用程序。有什么想法吗? - Andreas

1
如果有其他人来到这个页面,我成功地通过关闭以下设置来解决了这个问题:
工具 > 选项 > 调试 > 通用 > 启用 XAML UI 调试工具

1

我的快速解决方法是在调试配置期间禁用LayoutAutoHideWindowControl类中的UpdateWindowPos()。

    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()");
    }

根据我的经验,这只会导致无法拖放最小化的可停靠容器。

或者只需使用 #if !DEBUG(并省略 #ELSE - kmote

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接