Search code examples
visual-studio-2019fxcoproslyn-code-analysis

Opening the Code Analysis Ruleset editor crashes Visual Studio


Every time I try to do anything with Code Analysis, Visual Studio crashes. The event viewer shows the crash is caused by an invalid window-splitter size.

Stacktrace:

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentOutOfRangeException
   at System.Windows.Forms.SplitContainer.set_SplitterDistance(Int32)
   at Microsoft.VisualStudio.CodeAnalysis.AdvancedRuleSetEdit.LoadHelpPaneSizeString(System.String)
   at Microsoft.VisualStudio.CodeAnalysis.AdvancedRuleSetEdit.LoadHelpPaneSettings()
   at Microsoft.VisualStudio.CodeAnalysis.AdvancedRuleSetEdit.SplitterResized(System.Object, System.EventArgs)
   at System.Windows.Forms.Control.OnResize(System.EventArgs)
   at System.Windows.Forms.Control.OnSizeChanged(System.EventArgs)
   at System.Windows.Forms.Control.UpdateBounds(Int32, Int32, Int32, Int32, Int32, Int32)
   at System.Windows.Forms.Control.UpdateBounds()
   at System.Windows.Forms.Control.WmWindowPosChanged(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ContainerControl.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.SplitContainer.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr, Int32, IntPtr, IntPtr)

Solution

  • Procmon shows this value is stored in the private registry bin file.

    Deleting the window settings for Code Analysis fixes the cause of the crash. You may need to do this every time you close Visual Studio.

    Export from the private registry bin:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\vs2019\Software\Microsoft\VisualStudio\16.0_ad070b97\CodeAnalysis]
    "RuleSetMRUList"=""
    "RuleSelectionControl_Settings"="True,True,True,7,2,0,True,0;True;0.385#1;False;0.160#2;True;0.429#3;False;0.160#4;False;0.100#5;True;0.186#6;False;0.150#7;False;0.150#"
    "RuleSetEditorHelpPaneSize"="573,573"
    

    If you are running into this, to resolve:

    // put your instance id in the next line instead of ad070b97
    cd C:\Users\Administrator\AppData\Local\Microsoft\VisualStudio\16.0_ad070b97
    reg load HKLM\vs2019 privateregistry.bin
    reg delete HKLM\vs2019\Software\Microsoft\VisualStudio\16.0_ad070b97\CodeAnalysis /v RuleSetEditorHelpPaneSize
    reg unload HKLM\vs2019
    

    Fixed in latest VS 2019 versions