[New article]: A comprehensive reference of errors, warnings, and analysis rules.
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 370
Description
### 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](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/errors-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:
- https://github.com/dotnet/docs/issues/35750 (error leads nowhere*)
- https://github.com/dotnet/docs/issues/33667 (Confusion about enabling)
- https://github.com/dotnet/docs/issues/38348 ("latest" doesn't enable)
- https://github.com/dotnet/docs/issues/20796 (What are the defaults?)
- https://github.com/dotnet/docs/issues/33559 (WarningLevel/AnalysisLevel mismatch)
- etc./
*Links [this](https://github.com/dotnet/docs/blob/main/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md?plain=1#L331) 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](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/errors-warnings) and this article on [code quality rule configuration](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-quality-rule-options).
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:
- Compiler errors are always enabled.
- Diagnostics that are enabled by warning level X are also enabled at analysis level X
- Diagnostics that are enabled by warning level X are also enabled at warning levels X+Y
- Diagnostics that are enabled by analysis level X are also enabled at analysis level X+1
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](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0001)|
|CS0003|[Article](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0003)|
|...|...|
|CS9088|Currently undocumented.|
|etc|etc|
## Warnings
|Diagnostic code|Cause|Enabled by|
|-|-|-|
|CS0183|[Article](https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0183)|Warning level 1|
|CS0184|[Article](https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0184)|Warning level 1|
|...|...|...|
|CS8618|[Article](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings)|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](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1000)|Design|Hidden|
|...|...|...|...|
|CA1416|[Article](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416)|Interoperability|Warning
|etc|etc|etc|etc|
### Relevant searches
- warning
- analysis
- nullable
- error
- rule
- CS8618
- project
- properties
- dotnet build
- msbuild
- diagnostic
- wave
-
Contributor guide
Assessment
This issue has not been assessed yet.