Visual studio 2013 在使用 winforms 设计器时崩溃

Visual studio 2013 crashes while using winforms designer

Visual studio 当我在 winforms 设计器中使用拖放功能时,2013 经常崩溃,例如添加新控件、调整控件大小,或者只是单击控件以 see/change 的属性控制。 OS - Win 7x86, verson of VS - VS2013 ultimate 12.0.21005.1 rel. 我尝试 运行 VS 作为管理员,但它几乎仍然崩溃我使用拖放功能的时间。

我在 VS 的第二个实例(附加到第一个 VS 进程)的帮助下调试 VS,结果如下:(我 运行 它多次,看起来它抛出 3 个不同的一种例外)

An unhandled exception of type 'System.InvalidOperationException' occurred in System.Drawing.dll
Additional information: Object is currently in use elsewhere.

>   System.Drawing.dll!System.Drawing.Image.RawFormat.get() Unknown
    System.Drawing.dll!System.Drawing.Graphics.DrawImage(System.Drawing.Image image, int x, int y)  Unknown
    System.Design.dll!System.Windows.Forms.Design.Behavior.DesignerActionGlyph.Paint(System.Windows.Forms.PaintEventArgs pe)    Unknown

或者相同的异常但不同的调用堆栈:

>   System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, int x, int y, int width, int height)   Unknown
    System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect) Unknown
    System.Design.dll!System.Windows.Forms.Design.Behavior.SelectionBorderGlyph.Paint(System.Windows.Forms.PaintEventArgs pe)   Unknown

另一个例外:

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll 
Additional information: Exception has been thrown by the target of an invocation.


>   mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args)   Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) Unknown
    System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) Unknown

最后一个:

An unhandled exception of type 'System.AccessViolationException' occurred in System.Drawing.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

>   System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, int x, int y, int width, int height)   Unknown
    System.Drawing.dll!System.Drawing.Graphics.FillRectangle(System.Drawing.Brush brush, System.Drawing.Rectangle rect) Unknown
    System.Design.dll!System.Windows.Forms.Design.Behavior.SelectionBorderGlyph.Paint(System.Windows.Forms.PaintEventArgs pe)   Unknown

ETA: @GRUNGER 的回答有帮助,但问题是什么?

即使在新的空项目中也会崩溃。

我也遇到了同样的问题。鼠标光标在闪烁?

试试这个(在管理模式 CMD 下):

netsh winsock reset

有时有用,但重启后问题又来了。

这可能是因为在构造函数中放入了一些 dangerous/crashing 代码以阻止创建控件。重构您的代码并将其移至加载处理程序。