Search code examples
c#idevisual-studio-2019

#region sections not being recognised in Visual Studio 2019


Running Visual Studio Professional 2019 v16.11.16.

My .NET solution has several C# and VB.NET modules with #region\#endregion and #Region\#End Region sections. The existing regions in the VB modules have a "+" or "-" in the left margin and can be collapsed or expanded as normal.

But new and existing regions are not being recognised in the .cs files:

#region Test region
// Nothing appears in the margin at any time and block cannot be collapsed
#endregion

Confusingly, in some .cs files existing regions are recognised! But in no .cs file are new #region sections being recognised.

Although working in .vb files, if there is any syntax error anywhere in the #Region\#End Region block, the region stops being recognised and the icon disappears.

New classes, methods, try/catch, if statements, etc. in .cs files are being recognised as code blocks and can be collapsed/expanded as normal.

What setting(s) affect #region identification? Could something be broken in a recent VS 2019 update?


Solution

  • Clearing the cache and the following folders did not help:

    • %USERPROFILE%\AppData\Local\Temp
    • %USERPROFILE%\AppData\Local\Microsoft\Team Foundation
    • %USERPROFILE%\AppData\Local\Microsoft\VisualStudio
    • %USERPROFILE%\AppData\Local\Microsoft\VSCommon

    A clue was the difference between C# and VB. So after hunting through settings specific for C# I finally found the setting:

    Tools > Options > Text Editor > C# > Advanced > Outlining > Show outlining for comments and preprocessor regions

    Turning that on resolved the problem. Not sure when or why that was turned off. Hope this helps someone else.