-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add help for various C# 11 diagnostics #51329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Also, add new C# 15 errors to catch-all file
Focus on fixing the error, not describing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds documentation for several C# 11 compiler diagnostics by moving them from the generic error page to appropriate thematic documentation files, and enhances the source generator documentation with actionable guidance.
Changes:
- Removed CS9027, CS9041, CS9049, and CS9067 from the generic "sorry we don't have specifics" error file
- Added CS9049 (ref field in fixed-size buffer) to unsafe code errors documentation
- Added CS9027 (unexpected unchecked keyword) to operator errors documentation
- Added CS9041 (unsupported compiler feature) to feature version errors documentation
- Added CS9057 (analyzer version compatibility) and CS9067 (duplicate analyzer reference) to source generator errors documentation with detailed resolution guidance
- Updated table of contents to reflect the new error code locations
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md | Removed CS9027, CS9041, CS9049, and CS9067 from the generic error list; added C# 15 diagnostics placeholder |
| docs/csharp/language-reference/toc.yml | Added error codes to appropriate category display names in table of contents |
| docs/csharp/language-reference/compiler-messages/unsafe-code-errors.md | Added CS9049 documentation explaining that fixed fields cannot be ref fields |
| docs/csharp/language-reference/compiler-messages/source-generator-errors.md | Added CS9057 and CS9067 with new "Analyzer compatibility" section providing detailed resolution guidance |
| docs/csharp/language-reference/compiler-messages/overloaded-operator-errors.md | Added CS9027 documentation for unexpected unchecked keyword in operator declarations |
| docs/csharp/language-reference/compiler-messages/feature-version-errors.md | Added CS9041 to the list of compiler feature/version errors |
docs/csharp/language-reference/compiler-messages/source-generator-errors.md
Show resolved
Hide resolved
docs/csharp/language-reference/compiler-messages/source-generator-errors.md
Show resolved
Hide resolved
docs/csharp/language-reference/compiler-messages/source-generator-errors.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/compiler-messages/source-generator-errors.md
Outdated
Show resolved
Hide resolved
docs/csharp/language-reference/compiler-messages/overloaded-operator-errors.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Meaghan Osagie (Lewis) <[email protected]>
gewarren
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry a bit late but putting these comments here just in case they're helpful.
| - **CS8929**: *Method cannot implement interface member in type because the target runtime doesn't support static abstract members in interfaces.* | ||
| - **CS8957**: *Conditional expression is not valid in language version because a common type was not found between types.* | ||
| - **CS8967**: *Newlines inside a non-verbatim interpolated string are not supported in C#* | ||
| - **CS9041**: *Requires compiler feature, which is not supported by this version of the C# compiler.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - **CS9041**: *Requires compiler feature, which is not supported by this version of the C# compiler.* | |
| - **CS9041**: *Requires a compiler feature that is not supported by this version of the C# compiler.* |
| In C# 12, interceptors are experimental. Interceptors are subject to breaking changes or removal in a future release. Therefore, it is not recommended for production or released applications. | ||
|
|
||
| In order to use interceptors, you must set the `<Features>InterceptorsPreview</Features>` element in your project file. Without this flag, interceptors are disabled, even when other C# 12 features are enabled. | ||
| To use interceptors, add the `<Features>InterceptorsPreview</Features>` element to your project file within a `<PropertyGroup>` section (**CS9137**), because interceptors are an experimental feature that isn't enabled by default. This explicit opt-in is required because interceptors are subject to breaking changes or removal in future releases, and the compiler needs confirmation that you understand the risks before allowing their use. For more information about interceptors and their capabilities, see [Interceptors](../../whats-new/csharp-12.md#interceptors) in the C# 12 features documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| To use interceptors, add the `<Features>InterceptorsPreview</Features>` element to your project file within a `<PropertyGroup>` section (**CS9137**), because interceptors are an experimental feature that isn't enabled by default. This explicit opt-in is required because interceptors are subject to breaking changes or removal in future releases, and the compiler needs confirmation that you understand the risks before allowing their use. For more information about interceptors and their capabilities, see [Interceptors](../../whats-new/csharp-12.md#interceptors) in the C# 12 features documentation. | |
| To use interceptors, add the `<Features>InterceptorsPreview</Features>` element to your project file within a `<PropertyGroup>` section (**CS9137**), because interceptors is an experimental feature that isn't enabled by default. This explicit opt-in is required because the interceptors feature is subject to breaking changes or removal in future releases, and the compiler needs confirmation that you understand the risks before allowing its use. For more information about interceptors and their capabilities, see [Interceptors](../../whats-new/csharp-12.md#interceptors) in the C# 12 features documentation. |
| - **CS9161** prevents interceptors from being marked with `UnmanagedCallersOnlyAttribute`. | ||
| - **CS9206** requires interceptors to be contained in a namespace (not global). | ||
| - **CS9207** requires interceptable methods to be ordinary member invocations. | ||
| - **CS9057** is generated when an analyzer assembly references a version of the Roslyn compiler that is newer than the one currently running. This prevents the analyzer from loading because it may depend on APIs or behaviors not available in the current compiler version. To resolve this, either upgrade your compiler/SDK to match the analyzer's requirements or use a version of the analyzer compatible with your current compiler version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - **CS9057** is generated when an analyzer assembly references a version of the Roslyn compiler that is newer than the one currently running. This prevents the analyzer from loading because it may depend on APIs or behaviors not available in the current compiler version. To resolve this, either upgrade your compiler/SDK to match the analyzer's requirements or use a version of the analyzer compatible with your current compiler version. | |
| - **CS9057** is generated when an analyzer assembly references a version of the Roslyn compiler that is newer than the one currently running. This prevents the analyzer from loading because it might depend on APIs or behaviors not available in the current compiler version. To resolve this, either upgrade your compiler/SDK to match the analyzer's requirements or use a version of the analyzer compatible with your current compiler version. |
| - **CS9206** requires interceptors to be contained in a namespace (not global). | ||
| - **CS9207** requires interceptable methods to be ordinary member invocations. | ||
| - **CS9057** is generated when an analyzer assembly references a version of the Roslyn compiler that is newer than the one currently running. This prevents the analyzer from loading because it may depend on APIs or behaviors not available in the current compiler version. To resolve this, either upgrade your compiler/SDK to match the analyzer's requirements or use a version of the analyzer compatible with your current compiler version. | ||
| - **CS9067** warns when the same analyzer assembly is referenced multiple times in your project. This typically happens when an analyzer is included through multiple paths or package references. While not an error, duplicate references can impact build performance and may cause unexpected behavior. Remove the duplicate references to resolve this warning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - **CS9067** warns when the same analyzer assembly is referenced multiple times in your project. This typically happens when an analyzer is included through multiple paths or package references. While not an error, duplicate references can impact build performance and may cause unexpected behavior. Remove the duplicate references to resolve this warning. | |
| - **CS9067** warns when the same analyzer assembly is referenced multiple times in your project. This typically happens when an analyzer is included through multiple paths or package references. While not an error, duplicate references can impact build performance and might cause unexpected behavior. Remove the duplicate references to resolve this warning. |
Fixes #49599
Newer files for these themes already existed, so add these diagnostics to the appropriate file.
In the case of source generators, update the file to provide recommendations on addressing the error, rather than merely descxribing it.
Internal previews