dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.21k stars 5.87k forks source link

[New article]: A comprehensive reference of errors, warnings, and analysis rules. #39274

Open SRNissen opened 7 months ago

SRNissen commented 7 months ago

Proposed topic or title

Comprehensive overview of diagnostic codes

Location in table of Contents.

/csharp/language-reference/compiler-messages

Reason for the article

There is no comprehensive overview of compiler diagnostics and the ways you enable or disable them for your project.

I have experienced, over the years, that Visual Studio shows me a warning and, rather than linking a reference, it suggests how to find it with Bing!

You can read everything in Errors and Warnings and still not find out about the "CAxxxx" diagnostics or how to enable them, nor does that section have (or link to) a comprehensive overview even of the regular warnings and errors.

See also:

*Links this list.


I am aware that a comprehensive article documenting everything would be a daunting task. Merely listing everything might be an unreasonable ask.

But I could really use a one-stop shop that says, effectively: "If you've found this article, you have found all that we currently have to say on the subject."

Article abstract

Comprehensive overview of diagnostic codes

During compilation, the compiler may emit diagnostics about errors that prevent it from compiling, or warnings about code that can be compiled but is possibly wrong.

The emitted diagnostics are affected by your project settings, see this article on compiler options and this article on code quality rule configuration.

This article is a work in progress, some errors and warnings are currently undocumented.

If you require answers immediately, some information may be found by searching through the source code for your compiler. For example, to find an explanation for CS8618 in the Roslyn compiler, you could examine https://github.com/search?q=repo%3Adotnet/roslyn%20CS8618&type=code

Unless otherwise specified:

To receive all warnings, set warning level "9999" and analysis level "latest"

Example: CS0114 has warning level 2.

CS0114 Warning level 0 Warning level 4 Warning level 9999
Analysis level 0 Disabled enabled enabled
Analysis level 8 enabled enabled enabled
Analysis level latest enabled enabled enabled

Compiler errors

Diagnostic code Cause
CS0001 Article
CS0003 Article
... ...
CS9088 Currently undocumented.
etc etc

Warnings

Diagnostic code Cause Enabled by
CS0183 Article Warning level 1
CS0184 Article Warning level 1
... ... ...
CS8618 Article Warning level 1 AND nullable references must be enabled.
etc etc etc etc

Code analysis rules

Code analysis rules have a severity rather than a warning level. Projects that treat warnings as errors may build despite receiving Code Analysis diagnostics if those diagnostics are at a severity lower than "Warning."

Diagnostic code Cause Category Default severity
CA1000 Article Design Hidden
... ... ... ...
CA1416 Article Interoperability Warning
etc etc etc etc

Relevant searches

BillWagner commented 7 months ago

Hi @SRNissen

I like this idea. As I get further on coverage for more of the C# compiler error codes, I'll incorporate this.

Right now, I'm focusing on adding coverage for the error codes most often landing on the undocumented error codes page. I've been working with the compiler team to make sure this page has all the code we don't cover. That lets me see the traffic, and find the ones most often requested.

Each month, I check the data and build a new page with errors related to the most common terms used. As I do this, I am combining pages with errors and warnings related to features or scenarios. I'd like your thoughts on the general structure of those newer pages.

In a related note, I'm also working with the compiler team so that as new features are merged into the main branch in roslyn, I'm adding a new with all the errors and warnings related to that feature. That keeps us from falling farther behind.

As I get farther along, I'll add an index page like the one requested here. I don't think that page should have the F1 tags, as I think those queries should go to the pertinent page.

Thanks for the suggestion. I've added it to the "Everyday C#" project to address as I keep making progress.

SRNissen commented 7 months ago

I am happy to hear you like the idea.

I didn't want to write the whole thing up only to have the PR rejected as out of scope for the docs project. Given this reply, I'll take a stab at it.