Visual Studio Designer崩溃(在Windows 8上)

时间:2013-09-23 13:10:59

标签: visual-studio windows-8

我们遇到的问题是,尝试在Visual Studio(2010或2012)中打开特定的设计器文件会导致它无法恢复崩溃('Visual Studio已停止工作')。

在尝试此操作时将调试器附加到进程会抛出System.NullReferenceException,并显示堆栈跟踪:

at System.Windows.Forms.NativeWindow.AddWindowToTable(IntPtr handle, NativeWindow window)
at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
at System.Windows.Forms.Design.ControlDesigner.ChildSubClass..ctor(ControlDesigner designer, IntPtr hwnd)
at System.Windows.Forms.Design.ControlDesigner.HookChildHandles(IntPtr firstChild)
at System.Windows.Forms.Design.ControlDesigner.HookChildControls(Control firstChild)
at System.Windows.Forms.Design.ControlDesigner.HookChildControls(Control firstChild)
at System.Windows.Forms.Design.ControlDesigner.HookChildControls(Control firstChild)
at System.Windows.Forms.Design.ControlDesigner.HookChildControls(Control firstChild)
at System.Windows.Forms.Design.ControlDesigner.OnHandleChange()
at System.Windows.Forms.Design.ControlDesigner.DesignerWindowTarget.OnHandleChange(IntPtr newHandle)
at System.Windows.Forms.Control.ControlNativeWindow.OnHandleChange()
at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle, Boolean assignUniqueID)
at System.Windows.Forms.NativeWindow.AssignHandle(IntPtr handle)
at System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

此问题在我们更新到Windows 8 Enterprise(现在使用SSD)的开发框中始终显示。 Windows 7 Professional上较旧的框始终显示表现出此行为。这个问题似乎也只出现在特定的设计器文件中,但目前尚不清楚原因。

有没有人有任何解决此问题或进一步调查的建议?

1 个答案:

答案 0 :(得分:2)

从未完全解决此问题,但确实设计了一种解决方法。我在这里提交的错误报告中有更多信息(来自MS): http://connect.microsoft.com/VisualStudio/feedback/details/802088/designer-file-causing-crash-since-update-to-windows-8

总之,MS小组建议这是一个“..crash,当其中一个控件的静态初始化失败时”

通过反复试验,我们缩小了问题范围,以确定导致问题的控制,然后最小化其执行的初始化(但仅限于设计时间)

为了最小化初始化,我们添加了一个属性来检查控件是否在设计器中使用:

private bool IsDesignerHosted
{
    get
    {
        if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) return true;
        Control ctrl = this;
        while (ctrl != null)
        {
            if ((ctrl.Site != null) && ctrl.Site.DesignMode) return true;
            ctrl = ctrl.Parent;
        }
        return false;
    }
}

..然后在设计时使用此属性来阻止控件上的活动。

相关问题