[Feedback] Quality Rule CA1031 is listed in Visual Studio but ignored until manually added to .editorconfig
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
[Link to AzDO feedback work item](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2380820).
[Link to Developer Community feedback item](https://developercommunity.visualstudio.com/t/Quality-Rule-CA1031-is-listed-in-Visual-/10846511).
This is probably not specific to CA1031.
Repro steps:
Start a new .NET 8 console app project.
Add the following code to Program.cs. The IDE issues no warning for this code.
try { }
catch (InvalidCastException) { }
catch (Exception) { }
In the absence of proper guidelines here relevant to C#/.NET projects [here](https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022), attempt to dump project settings to .editorconfig like so:
3.1. Create an empty .editorconfig file in the project root.
3.2. Double-click the file in the Solution Explorer. (This apparently dumps some of the settings to the file.)
3.3. Save changes.
In the .editorconfig tab
4.1. Navigate to the Analyzers secondary tab.
4.2. Search for 1031. CA1031 is listed with severity and location set to Warning and Analyser Defaults respectively.
Return to Program.cs. The IDE still issues no warning for the code.
At the end of .editorconfig (under [*.cs]), add the following line and save the file:
dotnet_diagnostic. CA1031.severity = warning
Return to Program.cs. The IDE now shows a CA1031 warning for catch (Exception) { }.
At the end of .editorconfig (under [*.cs]), add the following line and save the file.
dotnet_code_quality. CA1031.disallowed_symbol_names = InvalidCastException
Return to Program.cs. The IDE now shows a CA1031 warning for catch (InvalidCastException) { }.
In .editorconfig, comment out the following line and save the file:
dotnet_diagnostic. CA1031.severity = warning
Both warnings are gone from Program.cs.
Questions:
Is this the expected behavior?
What is the right way to generate a .editorconfig file that takes into account the Analyzer Defaults in C#/.NET projects, so one only needs to modify a few default settings when needed?
Thanks.
To find diagnostic information, see the [original linked feedback ticket](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2380820).
Contributor guide
Assessment
This issue has not been assessed yet.