PaulG
PaulG

Reputation: 14021

Visual Studio Designer crashing (on Windows 8)

We're having an issue where trying to open specific designer files within Visual Studio (either 2010 or 2012) will cause it to crash unrecoverably ('Visual Studio has stopped working').

Attaching a debugger to the process when this is attempted throws a System.NullReferenceException, with stack trace:

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)

This issue appears consistently on the development boxes that we have updated to Windows 8 Enterprise (and now use SSDs). The older boxes on Windows 7 Professional consistently do not exhibit this behaviour. The issue also only seems to occur on specific designer files, though it is not clear yet why.

Does anyone have any suggestions for resolving this, or investigating further?

Upvotes: 1

Views: 536

Answers (1)

PaulG
PaulG

Reputation: 14021

Never fully resolved this issue, but did engineer a workaround. There is more info (from MS) in the bug report I submitted here: http://connect.microsoft.com/VisualStudio/feedback/details/802088/designer-file-causing-crash-since-update-to-windows-8

In summary, the MS team suggested this was a "..crash when static initialization for one of the controls was failing"

Through trial and error we narrowed down the issue to identify the control that was causing the issue, and then minimised the initialisation it was performing (but only in design time)

To minimise initialisation we added a property to check if the control was being used in designer:

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

.. then use this property to prevent activity on the control when in design time.

Upvotes: 2

Related Questions