From 251189cb0b7cdeab71fd4067aded37bfc6b66827 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 20 Oct 2025 11:40:34 -0400 Subject: [PATCH 1/8] checkpoint - scratch pad for errors Put the errors and the messages in one file for triage and moving into correct themes. --- .../compiler-messages/misc-12-errors.md | 79 +++++++++++++++++++ ...n-t-have-specifics-on-this-csharp-error.md | 17 ---- 2 files changed, 79 insertions(+), 17 deletions(-) create mode 100644 docs/csharp/language-reference/compiler-messages/misc-12-errors.md diff --git a/docs/csharp/language-reference/compiler-messages/misc-12-errors.md b/docs/csharp/language-reference/compiler-messages/misc-12-errors.md new file mode 100644 index 0000000000000..60c6fc88191b0 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/misc-12-errors.md @@ -0,0 +1,79 @@ +title: Remaining errors introduced in C# 12 +description: Not sure what the themes will be, but let's start +f1_keywords: + - "CS9123" + - "CS9125" + - "CS9205" + - "CS9212" + - "CS9213" + - "CS9214" + - "CS9215" + - "CS9222" + - "CS9229" + - "CS9230" + - "CS9231" + - "CS9232" + - "CS9233" + - "CS9234" + - "CS9235" + - "CS9236" +helpviewer_keywords: + - "CS9123" + - "CS9125" + - "CS9205" + - "CS9212" + - "CS9213" + - "CS9214" + - "CS9215" + - "CS9222" + - "CS9229" + - "CS9230" + - "CS9231" + - "CS9232" + - "CS9233" + - "CS9234" + - "CS9235" + - "CS9236" +ms.date: 10/10/2025 +--- +# Errors and warnings introduced in C# 12 + +The following errors and warnings were introduced in C# 12: + + + +Unsafe. +- [**CS9123**](#tbd): *The '&' operator should not be used on parameters or local variables in async methods.* + +Fixed sized buffers +- [**CS9125**](#tbd): *Attribute parameter 'SizeConst' must be specified.* + +Weird ref safety, based on passing an interpolated string as an `out` parameter. +- [**CS9205**](#tbd): *Expected interpolated string* + +// collection expressions +- [**CS9212**](#tbd): *Spread operator '..' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'* +- [**CS9213**](#tbd): *Collection expression target 'type' has no element type.* +- [**CS9214**](#tbd): *Collection expression type must have an applicable constructor that can be called with no arguments.* +- [**CS9215**](#tbd): *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.* +- [**CS9222**](#tbd): *Collection initializer results in an infinite chain of instantiations of collection 'type'.* + +invalid using declaration +- [**CS9229**](#tbd): *Modifiers cannot be placed on using declarations* + +dynamic binding +- [**CS9230**](#tbd): *Cannot perform a dynamic invocation on an expression with type 'type'.* + +interceptors +- [**CS9231**](#tbd): *The data argument to InterceptsLocationAttribute is not in the correct format.* +- [**CS9232**](#tbd): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* +- [**CS9233**](#tbd): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* +- [**CS9234**](#tbd): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* +- [**CS9235**](#tbd): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* + +lambda, but informational only +- [**CS9236**](#tbd): *Compiling requires binding the lambda expression at least count times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.* + + diff --git a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md index 59076a4fed587..2c04db37e8569 100644 --- a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md +++ b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md @@ -575,23 +575,6 @@ f1_keywords: - "CS9095" - "CS9096" - "CS9097" - # C# 12 errors begin here - - "CS9123" - - "CS9125" - - "CS9205" - - "CS9212" - - "CS9213" - - "CS9214" - - "CS9215" - - "CS9222" - - "CS9229" - - "CS9230" - - "CS9231" - - "CS9232" - - "CS9233" - - "CS9234" - - "CS9235" - - "CS9236" # C# 14 errors begin here - "CS9327" - "CS9328" From 4589ff0d7bc92a775138147313ed1e27cc1c0f61 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 20 Oct 2025 13:26:27 -0400 Subject: [PATCH 2/8] Move errors to correct theme. --- .../array-declaration-errors.md | 25 ++++++ .../compiler-messages/inline-array-errors.md | 4 + .../lambda-expression-errors.md | 11 +++ .../compiler-messages/misc-12-errors.md | 79 ------------------- .../compiler-messages/ref-modifiers-errors.md | 5 ++ .../source-generator-errors.md | 33 ++++++++ docs/csharp/language-reference/toc.yml | 11 +-- ...n-t-have-specifics-on-this-csharp-error.md | 4 + 8 files changed, 88 insertions(+), 84 deletions(-) delete mode 100644 docs/csharp/language-reference/compiler-messages/misc-12-errors.md diff --git a/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md b/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md index 05bf90416f684..1d7c1f324d95f 100644 --- a/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md +++ b/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md @@ -37,6 +37,11 @@ f1_keywords: - "CS9208" - "CS9209" - "CS9210" + - "CS9212" + - "CS9213" + - "CS9214" + - "CS9215" + - "CS9222" helpviewer_keywords: - "CS0022" - "CS0178" @@ -73,6 +78,11 @@ helpviewer_keywords: - "CS9208" - "CS9209" - "CS9210" + - "CS9212" + - "CS9213" + - "CS9214" + - "CS9215" + - "CS9222" ms.date: 11/02/2023 --- # Resolve errors and warnings in array and collection declarations and initialization expressions @@ -110,6 +120,11 @@ That's by design. The text closely matches the text of the compiler error / warn - [**CS9188**](#invalid-collection-builder): *Type has a CollectionBuilderAttribute but no element type.* - [**CS9203**](#invalid-collection-initializer): *A collection expression of this type cannot be used in this context because it may be exposed outside of the current scope.* - [**CS9210**](#invalid-collection-initializer): *This version of cannot be used with collection expressions.* +- [**CS9212**](#invalid-collection-initializer): *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'* +- [**CS9213**](#invalid-collection-initializer): *Collection expression target 'type' has no element type.* +- [**CS9214**](#invalid-collection-initializer): *Collection expression type must have an applicable constructor that can be called with no arguments.* +- [**CS9215**](#invalid-collection-initializer): *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.* +- [**CS9222**](#invalid-collection-initializer): *Collection initializer results in an infinite chain of instantiations of collection 'type'.* In addition, the following warnings are covered in this article: @@ -141,6 +156,11 @@ The following errors indicate that the code generated by the compiler for a coll - **CS9176**: *There is no target type for the collection literal.* - **CS9203**: *A collection expression of this type cannot be used in this context because it may be exposed outside of the current scope.* - **CS9210**: *This version of cannot be used with collection expressions.* +- **CS9212**: *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'* +- **CS9213**: *Collection expression target 'type' has no element type.* +- **CS9214**: *Collection expression type must have an applicable constructor that can be called with no arguments.* +- **CS9215**: *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.* +- **CS9222**: *Collection initializer results in an infinite chain of instantiations of collection 'type'.* The compiler might also generate the following warning: @@ -159,6 +179,11 @@ The errors all indicate that the code generated by the compiler for a collection - Collection expressions can initialize explicitly typed variables of a collection type. If the variable isn't a collection or array type, or is implicitly typed (using `var`), a collection initializer can't be used. - A `ref struct` type, like can't be initialized with a collection expression that may violate ref safety. - A collection expression can't correctly initialize an using the current version. Use a different version of the runtime, or change the initialization expression. +- The spread operator (`..`) in **CS9212** requires the type to implement a suitable method (like `GetEnumerator`) to enumerate its elements. Ensure your type implements the required enumeration pattern or provides an extension method. +- **CS9213** occurs when the compiler can't determine what element type to use for the collection expression. This typically happens with custom collection types. Make sure your collection type properly exposes its element type through its type definition or implements appropriate collection interfaces. +- **CS9214** is generated when a collection expression tries to initialize a type that doesn't have a parameterless constructor. Collection expressions require a constructor that can be called with no arguments to create the instance before adding elements. +- **CS9215** happens when the collection type doesn't provide an `Add` method that accepts a single parameter of the element type. The `Add` method must be accessible (typically public) and accept exactly one argument that matches the collection's element type. +- **CS9222** indicates a circular dependency in collection initialization. This occurs when initializing a collection triggers the creation of another instance of the same collection type, which in turn requires initializing another instance, creating an infinite loop. Review your collection type's constructor and initialization logic to break the circular dependency. The warnings indicates that the collection expression, including any [spread elements](../operators/collection-expressions.md#spread-element) might allocate memory. Creating different storage and converting might be more efficient. diff --git a/docs/csharp/language-reference/compiler-messages/inline-array-errors.md b/docs/csharp/language-reference/compiler-messages/inline-array-errors.md index d7a2438d26769..e55a0ade10b16 100644 --- a/docs/csharp/language-reference/compiler-messages/inline-array-errors.md +++ b/docs/csharp/language-reference/compiler-messages/inline-array-errors.md @@ -2,6 +2,7 @@ title: Resolve errors related to inline arrays description: These compiler errors and warnings are generated when you create an inline array struct that is invalid. This article helps you diagnose and fix those issues. f1_keywords: + - "CS9125" - "CS9164" - "CS9165" - "CS9166" @@ -18,6 +19,7 @@ f1_keywords: - "CS9189" - "CS9259" helpviewer_keywords: + - "CS9125" - "CS9164" - "CS9165" - "CS9166" @@ -42,6 +44,7 @@ This article covers the following compiler errors and warnings: +- [**CS9125**](#inline-array-declaration): *Attribute parameter 'SizeConst' must be specified.* - [**CS9164**](#conversions-to-span): *Cannot convert expression to `Span` because it is not an assignable variable* - [**CS9165**](#conversions-to-span): *Cannot convert expression to `ReadOnlySpan` because it may not be passed or returned by reference* - [**CS9166**](#element-access): *Index is outside the bounds of the inline array* @@ -62,6 +65,7 @@ That's by design. The text closely matches the text of the compiler error / warn You declare inline arrays as a `struct` type with a single field, and an attribute that specifies the length of the array. The compiler generates the following errors for invalid inline array declarations: +- **CS9125**: *Attribute parameter 'SizeConst' must be specified.* - **CS9167**: *Inline array length must be greater than 0.* - **CS9168**: *Inline array struct must not have explicit layout.* - **CS9169**: *Inline array struct must declare one and only one instance field which must not be a ref field.* diff --git a/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md b/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md index e612fc51b03fc..ce29ffdcd0c27 100644 --- a/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md +++ b/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md @@ -18,6 +18,7 @@ f1_keywords: - "CS9098" # ERR_ImplicitlyTypedDefaultParameter: Implicitly typed lambda parameter '{0}' cannot have a default value. - "CS9099" # WRN_OptionalParamValueMismatch: The default parameter value does not match in the target delegate type. - "CS9100" # WRN_ParamsArrayInLambdaOnly: Parameter has params modifier in lambda but not in target delegate type. + - "CS9236" # INF_TooManyBoundLambdas: Compiling requires binding the lambda expression at least {0} times. helpviewer_keywords: - "CS0748" - "CS0835" @@ -35,6 +36,7 @@ helpviewer_keywords: - "CS9098" - "CS9099" - "CS9100" + - "CS9236" ms.date: 05/04/2023 --- # Errors and warnings when using lambda expressions and anonymous functions @@ -64,6 +66,10 @@ In addition, there are several *warnings* related to declaring and using lambda - [**CS9099**](#lambda-expression-delegate-type): *The default parameter value does not match in the target delegate type.* - [**CS9100**](#lambda-expression-delegate-type): *Parameter has params modifier in lambda but not in target delegate type.* +The compiler also produces the following *informational* message: + +- [**CS9236**](#syntax-limitations-in-lambda-expressions): *Compiling requires binding the lambda expression at least count times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.* + ## Syntax limitations in lambda expressions Some C# syntax is prohibited in lambda expressions and anonymous methods. Using invalid constructs in a lambda expression causes the following errors: @@ -90,6 +96,11 @@ In addition, interpolated string handler types are ignored when applied to a lam - **CS8971**: *InterpolatedStringHandlerArgument has no effect when applied to lambda parameters and will be ignored at the call site.* +Certain expressions cause the compiler to emit the following informational warning: + +- **CS9236**: *Compiling requires binding the lambda expression at least count times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.* + +The complexity of the lambda expressions and how they invoke other lambda expressions is negatively impacting compiler performance. The reason is that the compiler must infer parameter and argument types through the lambda expressions and the potential types takes time. ## Lambda expression parameters and returns These errors indicate a problem with a parameter declaration: diff --git a/docs/csharp/language-reference/compiler-messages/misc-12-errors.md b/docs/csharp/language-reference/compiler-messages/misc-12-errors.md deleted file mode 100644 index 60c6fc88191b0..0000000000000 --- a/docs/csharp/language-reference/compiler-messages/misc-12-errors.md +++ /dev/null @@ -1,79 +0,0 @@ -title: Remaining errors introduced in C# 12 -description: Not sure what the themes will be, but let's start -f1_keywords: - - "CS9123" - - "CS9125" - - "CS9205" - - "CS9212" - - "CS9213" - - "CS9214" - - "CS9215" - - "CS9222" - - "CS9229" - - "CS9230" - - "CS9231" - - "CS9232" - - "CS9233" - - "CS9234" - - "CS9235" - - "CS9236" -helpviewer_keywords: - - "CS9123" - - "CS9125" - - "CS9205" - - "CS9212" - - "CS9213" - - "CS9214" - - "CS9215" - - "CS9222" - - "CS9229" - - "CS9230" - - "CS9231" - - "CS9232" - - "CS9233" - - "CS9234" - - "CS9235" - - "CS9236" -ms.date: 10/10/2025 ---- -# Errors and warnings introduced in C# 12 - -The following errors and warnings were introduced in C# 12: - - - -Unsafe. -- [**CS9123**](#tbd): *The '&' operator should not be used on parameters or local variables in async methods.* - -Fixed sized buffers -- [**CS9125**](#tbd): *Attribute parameter 'SizeConst' must be specified.* - -Weird ref safety, based on passing an interpolated string as an `out` parameter. -- [**CS9205**](#tbd): *Expected interpolated string* - -// collection expressions -- [**CS9212**](#tbd): *Spread operator '..' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'* -- [**CS9213**](#tbd): *Collection expression target 'type' has no element type.* -- [**CS9214**](#tbd): *Collection expression type must have an applicable constructor that can be called with no arguments.* -- [**CS9215**](#tbd): *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.* -- [**CS9222**](#tbd): *Collection initializer results in an infinite chain of instantiations of collection 'type'.* - -invalid using declaration -- [**CS9229**](#tbd): *Modifiers cannot be placed on using declarations* - -dynamic binding -- [**CS9230**](#tbd): *Cannot perform a dynamic invocation on an expression with type 'type'.* - -interceptors -- [**CS9231**](#tbd): *The data argument to InterceptsLocationAttribute is not in the correct format.* -- [**CS9232**](#tbd): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* -- [**CS9233**](#tbd): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* -- [**CS9234**](#tbd): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* -- [**CS9235**](#tbd): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* - -lambda, but informational only -- [**CS9236**](#tbd): *Compiling requires binding the lambda expression at least count times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.* - - diff --git a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md index bd5adb8e581e8..3e472462c0703 100644 --- a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md +++ b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md @@ -66,6 +66,7 @@ f1_keywords: - "CS9199" - "CS9200" - "CS9201" + - "CS9205" - "CS9265" helpviewer_keywords: - "CS0192" @@ -132,6 +133,7 @@ helpviewer_keywords: - "CS9199" - "CS9200" - "CS9201" + - "CS9205" - "CS9265" ms.date: 11/06/2024 --- @@ -209,6 +211,7 @@ The following warnings are generated when reference variables are used incorrect - [**CS9198**](#reference-variable-restrictions): *Reference kind modifier of parameter doesn't match the corresponding parameter in target.* - [**CS9200**](#reference-variable-restrictions): *A default value is specified for `ref readonly` parameter, but `ref readonly` should be used only for references. Consider declaring the parameter as `in`.* - [**CS9201**](#reference-variable-restrictions): *Ref field should be ref-assigned before use.* +- [**CS9205**](#incorrect-syntax): *Expected interpolated string* - [**CS9265**](#reference-variable-restrictions): *Field is never ref-assigned to, and will always have its default value (null reference)* These errors and warnings follow these themes: @@ -228,12 +231,14 @@ These errors indicate that you're using incorrect syntax regarding reference var - **CS8373**: *The left-hand side of a `ref` assignment must be a ref variable.* - **CS8388**: *An `out` variable cannot be declared as a ref local.* - **CS9190**: *`readonly` modifier must be specified after `ref`.* +- **CS9205**: *Expected interpolated string* You can correct the error with one of these changes: - The left operand of an `= ref` operator must be a reference variable. For more information on the correct syntax, see [reference variables](../statements/declarations.md#reference-variables). - The parameter modifier `ref readonly` must be in that order. `readonly ref` is not a legal parameter modifier. Switch the order of the words. - A local variable can't be declared as `out`. To declare a local reference variable, use `ref`. +- An `out` argument can't be an interpolated string. ## Reference variable restrictions diff --git a/docs/csharp/language-reference/compiler-messages/source-generator-errors.md b/docs/csharp/language-reference/compiler-messages/source-generator-errors.md index bb32eddc74871..f2dde755ec31f 100644 --- a/docs/csharp/language-reference/compiler-messages/source-generator-errors.md +++ b/docs/csharp/language-reference/compiler-messages/source-generator-errors.md @@ -31,6 +31,11 @@ f1_keywords: - "CS9178" - "CS9206" - "CS9207" + - "CS9231" + - "CS9232" + - "CS9233" + - "CS9234" + - "CS9235" - "CS9270" helpviewer_keywords: - "CS9137" @@ -62,6 +67,11 @@ helpviewer_keywords: - "CS9178" - "CS9206" - "CS9207" + - "CS9231" + - "CS9232" + - "CS9233" + - "CS9234" + - "CS9235" - "CS9270" ms.date: 05/23/2025 --- @@ -95,6 +105,11 @@ The following errors are generated when source generators or interceptors are lo - [**CS9178**](#signature-mismatch): *Method must be non-generic to match* - [**CS9206**](#other-failures): *An interceptor cannot be declared in the global namespace.* - [**CS9207**](#other-failures): *Cannot intercept because method is not an invocation of an ordinary member method.* +- [**CS9231**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute is not in the correct format.* +- [**CS9232**](#interceptslocationattribute-errors): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* +- [**CS9233**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* +- [**CS9234**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* +- [**CS9235**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* The following warnings are generated when source generators or interceptors are loaded during a compilation: @@ -160,6 +175,24 @@ Interceptors require a source mapping that maps the interceptable method and the An interceptor specifies the location in the source code of the interceptable method. You specify the location by applying an `[InterceptsLocation]` attribute. You specify the line and column numbers in a remapped source file where the interceptor should be injected. These errors indicate that something in the attribute or the location doesn't match a location for a valid interceptable method. For details on the format and values for this attribute, see the [feature specification](https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md#interceptslocationattribute). +## InterceptsLocationAttribute errors + +The following errors indicate issues with the `InterceptsLocationAttribute` format or the data provided to it: + +- **CS9231**: *The data argument to InterceptsLocationAttribute is not in the correct format.* +- **CS9232**: *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* +- **CS9233**: *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* +- **CS9234**: *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* +- **CS9235**: *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* + +These errors occur when the `InterceptsLocationAttribute` contains invalid data: + +- **CS9231** is generated when the data format doesn't match the expected structure. The attribute requires specifically formatted data that encodes the file path and position information. +- **CS9232** indicates you're using a version number that isn't supported. The interceptors feature uses version '1' format. Update your source generator to use the supported version. +- **CS9233** happens when the compilation contains multiple files with the same path, making it ambiguous which file to intercept in. Ensure each file in your compilation has a unique path. +- **CS9234** is emitted when the file path specified in the attribute doesn't match any file in the current compilation. Verify the file path is correct and the file is included in the compilation. +- **CS9235** occurs when the position data (line and character numbers) points to an invalid location in the specified file. This can happen if the position is outside the file's bounds or doesn't correspond to a valid interception point. + ## Other failures These errors indicate other limitations for interceptors: diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index 3b1858ef70716..5deb522f27944 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -504,7 +504,7 @@ items: CS7084, CS8166, CS8167, CS8168, CS8169. CS8325, CS8326, CS8327, CS8329, CS8330, CS8331, CS8332, CS8337, CS8338, CS8351, CS8373, CS8374, CS8388, CS8977, CS9072, CS9077, CS9078, CS9079, CS9085, CS9086, CS9087, CS9089, CS9091, CS9092, CS9093, CS9094, CS9095, CS9096, CS9097, CS9101, CS9102, CS9104, CS9190, CS9191, CS9192, CS9193, CS9195, CS9196, CS9197, CS9198, - CS9199, CS9200, CS9201, CS9265 + CS9199, CS9200, CS9201, CS9205, CS9265 - name: "`ref struct` types" href: ./compiler-messages/ref-struct-errors.md displayName: > @@ -555,15 +555,15 @@ items: displayName: > CS0022, CS0178, CS0248, CS0251, CS0270, CS0611, CS0623, CS0650, CS0719, CS0747, CS0820, CS0826, CS0846, CS1062, CS1063, CS1064, CS1552, CS1586, CS1920, CS1921, CS1925, CS1950, CS1954, CS3007, CS3016, CS9174, CS9176, CS9185, CS9186, CS9187, - CS9188, CS9203, CS9208, CS9209, CS9210 + CS9188, CS9203, CS9208, CS9209, CS9210, CS9212, CS9213, CS9214, CS9215, CS9222 - name: Inline arrays href: ./compiler-messages/inline-array-errors.md - displayName: CS9164, CS9165, CS9166, CS9167, CS9168, CS9169, CS9172, CS9173, CS9180, CS9181, CS9182, CS9183, CS9184, CS9259 + displayName: CS9125, CS9164, CS9165, CS9166, CS9167, CS9168, CS9169, CS9172, CS9173, CS9180, CS9181, CS9182, CS9183, CS9184, CS9259 - name: Lambda expressions href: ./compiler-messages/lambda-expression-errors.md displayName: > CS0748, CS1621, CS1628, CS1632, CS1673, CS1686, CS1706, CS1989, CS3006, CS8030, CS8175, CS8916, CS8971, CS8972, CS8975, CS9098, - CS9099, CS9100 + CS9099, CS9100, CS9236 - name: Overload resolution href: ./compiler-messages/overload-resolution.md displayName: > @@ -585,7 +585,8 @@ items: href: ./compiler-messages/source-generator-errors.md displayName: > CS9137, CS9138, CS9139, CS9140, CS9141, CS9142, CS9143, CS9144, CS9145, CS9146, CS9147, CS9148, CS9149, CS9150, CS9151, - CS9152, CS9153, CS9154, CS9155, CS9156, CS9157, CS9158, CS9159, CS9160, CS9161, CS9177, CS9178, CS9206, CS9207, CS9270 + CS9152, CS9153, CS9154, CS9155, CS9156, CS9157, CS9158, CS9159, CS9160, CS9161, CS9177, CS9178, CS9206, CS9207, CS9231, + CS9232, CS9233, CS9234, CS9235, CS9270 - name: static abstract interface members href: ./compiler-messages/static-abstract-interfaces.md displayName: CS8920, CS8921, CS8922, CS8923, CS8924, CS8925, CS8926, CS8928, CS8930, 8931, 8932 diff --git a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md index 2c04db37e8569..19935adcc92bd 100644 --- a/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md +++ b/docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md @@ -575,6 +575,10 @@ f1_keywords: - "CS9095" - "CS9096" - "CS9097" +# C# 12 errors begin here + - "CS9123" # The '&' operator should not be used on parameters or local variables in async methods. (new unsafe file) + - "CS9229" # Modifiers cannot be placed on using declarations (using declarations) + - "CS9230" # Cannot perform a dynamic invocation on an expression with type 'type'. (dynamic binding) # C# 14 errors begin here - "CS9327" - "CS9328" From f676788f36343d61863842b6c5c479bdcf402184 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 20 Oct 2025 13:31:35 -0400 Subject: [PATCH 3/8] Final edits --- .../source-generator-errors.md | 70 ++++++++----------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/source-generator-errors.md b/docs/csharp/language-reference/compiler-messages/source-generator-errors.md index f2dde755ec31f..04b294c3c533a 100644 --- a/docs/csharp/language-reference/compiler-messages/source-generator-errors.md +++ b/docs/csharp/language-reference/compiler-messages/source-generator-errors.md @@ -80,7 +80,7 @@ ms.date: 05/23/2025 The following errors are generated when source generators or interceptors are loaded during a compilation: - [**CS9137**](#interceptors-are-experimental): *The 'interceptors' experimental feature is not enabled. Add `InterceptorsPreview` to your project.* -- [**CS9138**](#other-failures): *Method cannot be used as an interceptor because it or its containing type has type parameters.* +- [**CS9138**](#incorrect-interceptor-declaration): *Method cannot be used as an interceptor because it or its containing type has type parameters.* - [**CS9139**](#incorrect-mapping): *Cannot intercept: compilation does not contain a file with path.* - [**CS9140**](#incorrect-mapping): *Cannot intercept: compilation does not contain a file with path. Did you mean to use a different path?* - [**CS9141**](#incorrect-mapping): *The provided line and character number does not refer to an interceptable method name, but rather to a token.* @@ -88,28 +88,28 @@ The following errors are generated when source generators or interceptors are lo - [**CS9143**](#incorrect-mapping): *The given line is `c` characters long, which is fewer than the provided character number `n`.* - [**CS9144**](#signature-mismatch): *Cannot intercept method `M` with interceptor `V` because the signatures do not match.* - [**CS9145**](#incorrect-mapping): *Cannot intercept: Path is unmapped. Expected mapped path.* -- [**CS9146**](#other-failures): *An interceptor method must be an ordinary member method.* +- [**CS9146**](#incorrect-interceptor-declaration): *An interceptor method must be an ordinary member method.* - [**CS9147**](#incorrect-mapping): *The provided line and character number does not refer to the start of a token. Did you mean to use line `n` and character `c`?* - [**CS9148**](#signature-mismatch): *Interceptor must have a `this` parameter matching parameter.* - [**CS9149**](#signature-mismatch): *Interceptor must not have a `this` parameter because method does not have a `this` parameter.* - [**CS9150**](#incorrect-mapping): *Interceptor cannot have a `null` file path.* -- [**CS9151**](#other-failures): *Possible method name `M` cannot be intercepted because it is not being invoked.* -- [**CS9152**](#other-failures): *Cannot intercept a call in file with this path because multiple files in the compilation have this path.* -- [**CS9153**](#other-failures): *The indicated call is intercepted multiple times.* +- [**CS9151**](#incorrect-interceptor-declaration): *Possible method name `M` cannot be intercepted because it is not being invoked.* +- [**CS9152**](#incorrect-interceptor-declaration): *Cannot intercept a call in file with this path because multiple files in the compilation have this path.* +- [**CS9153**](#incorrect-interceptor-declaration): *The indicated call is intercepted multiple times.* - [**CS9155**](#signature-mismatch): *Cannot intercept call with `M` because it is not accessible within `V`.* - [**CS9156**](#signature-mismatch): *Cannot intercept call to `M` with `V` because of a difference in 'scoped' modifiers or `[UnscopedRef]` attributes.* - [**CS9157**](#incorrect-mapping): *Line and character numbers provided to `InterceptsLocationAttribute` must be positive.* -- [**CS9160**](#other-failures): *A nameof operator cannot be intercepted.* -- [**CS9161**](#other-failures): *An interceptor cannot be marked with `UnmanagedCallersOnlyAttribute`.* +- [**CS9160**](#incorrect-interceptor-declaration): *A nameof operator cannot be intercepted.* +- [**CS9161**](#incorrect-interceptor-declaration): *An interceptor cannot be marked with `UnmanagedCallersOnlyAttribute`.* - [**CS9177**](#signature-mismatch): *Interceptor must be non-generic or have matching arity.* - [**CS9178**](#signature-mismatch): *Method must be non-generic to match* -- [**CS9206**](#other-failures): *An interceptor cannot be declared in the global namespace.* -- [**CS9207**](#other-failures): *Cannot intercept because method is not an invocation of an ordinary member method.* -- [**CS9231**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute is not in the correct format.* -- [**CS9232**](#interceptslocationattribute-errors): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* -- [**CS9233**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* -- [**CS9234**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* -- [**CS9235**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* +- [**CS9206**](#incorrect-interceptor-declaration): *An interceptor cannot be declared in the global namespace.* +- [**CS9207**](#incorrect-interceptor-declaration): *Cannot intercept because method is not an invocation of an ordinary member method.* +- [**CS9231**](#incorrect-interceptor-declaration): *The data argument to InterceptsLocationAttribute is not in the correct format.* +- [**CS9232**](#incorrect-interceptor-declaration): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* +- [**CS9233**](#incorrect-interceptor-declaration): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* +- [**CS9234**](#incorrect-interceptor-declaration): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* +- [**CS9235**](#incorrect-interceptor-declaration): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* The following warnings are generated when source generators or interceptors are loaded during a compilation: @@ -173,30 +173,15 @@ Interceptors require a source mapping that maps the interceptable method and the - **CS9150**: *Interceptor cannot have a `null` file path.* - **CS9157**: *Line and character numbers provided to `InterceptsLocationAttribute` must be positive.* -An interceptor specifies the location in the source code of the interceptable method. You specify the location by applying an `[InterceptsLocation]` attribute. You specify the line and column numbers in a remapped source file where the interceptor should be injected. These errors indicate that something in the attribute or the location doesn't match a location for a valid interceptable method. For details on the format and values for this attribute, see the [feature specification](https://github.com/dotnet/roslyn/blob/main/docs/features/interceptors.md#interceptslocationattribute). +## Incorrect interceptor declaration -## InterceptsLocationAttribute errors - -The following errors indicate issues with the `InterceptsLocationAttribute` format or the data provided to it: +The following errors indicate issues with interceptor declarations, including problems with the `InterceptsLocationAttribute` format or violations of interceptor rules: - **CS9231**: *The data argument to InterceptsLocationAttribute is not in the correct format.* - **CS9232**: *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.* - **CS9233**: *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.* - **CS9234**: *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.* - **CS9235**: *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.* - -These errors occur when the `InterceptsLocationAttribute` contains invalid data: - -- **CS9231** is generated when the data format doesn't match the expected structure. The attribute requires specifically formatted data that encodes the file path and position information. -- **CS9232** indicates you're using a version number that isn't supported. The interceptors feature uses version '1' format. Update your source generator to use the supported version. -- **CS9233** happens when the compilation contains multiple files with the same path, making it ambiguous which file to intercept in. Ensure each file in your compilation has a unique path. -- **CS9234** is emitted when the file path specified in the attribute doesn't match any file in the current compilation. Verify the file path is correct and the file is included in the compilation. -- **CS9235** occurs when the position data (line and character numbers) points to an invalid location in the specified file. This can happen if the position is outside the file's bounds or doesn't correspond to a valid interception point. - -## Other failures - -These errors indicate other limitations for interceptors: - - **CS9138**: *Method cannot be used as an interceptor because it or its containing type has type parameters.* - **CS9146**: *An interceptor method must be an ordinary member method.* - **CS9151**: *Possible method name `M` cannot be intercepted because it is not being invoked.* @@ -207,12 +192,19 @@ These errors indicate other limitations for interceptors: - **CS9206**: *An interceptor cannot be declared in the global namespace.* - **CS9207**: *Cannot intercept because method is not an invocation of an ordinary member method.* -These errors indicate that your interceptor method violates one of the rules for interceptors: +These errors occur when interceptor declarations violate the rules for interceptors or when the `InterceptsLocationAttribute` contains invalid data: -- Interceptors can't be generic methods, or members of generic classes. -- Interceptors must be ordinary members. They can't be operators, instance or static constructors, or finalizers. -- Interceptable methods must be ordinary members. They can't be operators, instance or static constructors, or finalizers, nor delegate invocations. -- Interceptable methods that are never invoked can't be intercepted. -- Interceptable methods can be intercepted at most once. -- Interceptors can't be methods limited to unmanaged callers. -- Interceptors must be contained in a namespace. +- **CS9231** is generated when the data format doesn't match the expected structure. The attribute requires specifically formatted data that encodes the file path and position information. +- **CS9232** indicates you're using a version number that isn't supported. The interceptors feature uses version '1' format. Update your source generator to use the supported version. +- **CS9233** happens when the compilation contains multiple files with the same path, making it ambiguous which file to intercept in. Ensure each file in your compilation has a unique path. +- **CS9234** is emitted when the file path specified in the attribute doesn't match any file in the current compilation. Verify the file path is correct and the file is included in the compilation. +- **CS9235** occurs when the position data (line and character numbers) points to an invalid location in the specified file. This can happen if the position is outside the file's bounds or doesn't correspond to a valid interception point. +- **CS9138** prevents generic methods or members of generic classes from being interceptors. +- **CS9146** requires interceptors to be ordinary members (not operators, constructors, or finalizers). +- **CS9151** prevents intercepting methods that are never invoked. +- **CS9152** detects duplicate file paths in the compilation. +- **CS9153** prevents multiple interceptions of the same call. +- **CS9160** prevents intercepting `nameof` operators. +- **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. From fd4a6a6b1ea77ebb64a89870dfb95a91c5dc8e2b Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 20 Oct 2025 13:34:45 -0400 Subject: [PATCH 4/8] Update docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../compiler-messages/lambda-expression-errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md b/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md index ce29ffdcd0c27..2cc63a20345bf 100644 --- a/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md +++ b/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md @@ -100,7 +100,7 @@ Certain expressions cause the compiler to emit the following informational warni - **CS9236**: *Compiling requires binding the lambda expression at least count times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.* -The complexity of the lambda expressions and how they invoke other lambda expressions is negatively impacting compiler performance. The reason is that the compiler must infer parameter and argument types through the lambda expressions and the potential types takes time. +The complexity of the lambda expressions and how they invoke other lambda expressions is negatively impacting compiler performance. The reason is that the compiler must infer parameter and argument types through the lambda expressions and the potential types take time. ## Lambda expression parameters and returns These errors indicate a problem with a parameter declaration: From 18600b6c1c597b98ff7fe8fe84c36a5e19ae6f3f Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Mon, 20 Oct 2025 13:40:03 -0400 Subject: [PATCH 5/8] fix build warnings --- .../compiler-messages/lambda-expression-errors.md | 1 + .../compiler-messages/source-generator-errors.md | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md b/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md index ce29ffdcd0c27..0d3ddb3a00a91 100644 --- a/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md +++ b/docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md @@ -101,6 +101,7 @@ Certain expressions cause the compiler to emit the following informational warni - **CS9236**: *Compiling requires binding the lambda expression at least count times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.* The complexity of the lambda expressions and how they invoke other lambda expressions is negatively impacting compiler performance. The reason is that the compiler must infer parameter and argument types through the lambda expressions and the potential types takes time. + ## Lambda expression parameters and returns These errors indicate a problem with a parameter declaration: diff --git a/docs/csharp/language-reference/compiler-messages/source-generator-errors.md b/docs/csharp/language-reference/compiler-messages/source-generator-errors.md index 04b294c3c533a..6b30f90f969bb 100644 --- a/docs/csharp/language-reference/compiler-messages/source-generator-errors.md +++ b/docs/csharp/language-reference/compiler-messages/source-generator-errors.md @@ -113,8 +113,8 @@ The following errors are generated when source generators or interceptors are lo The following warnings are generated when source generators or interceptors are loaded during a compilation: -- [**CS8784**](#other-failures): *Generator '`YourSourceGeneratorName`' failed to initialize. It will not contribute to the output and compilation errors may occur as a result.* -- [**CS8785**](#other-failures): *Generator '`YourSourceGeneratorName`' failed to generate source. It will not contribute to the output and compilation errors may occur as a result.* +- [**CS8784**](#incorrect-interceptor-declaration): *Generator '`YourSourceGeneratorName`' failed to initialize. It will not contribute to the output and compilation errors may occur as a result.* +- [**CS8785**](#incorrect-interceptor-declaration): *Generator '`YourSourceGeneratorName`' failed to generate source. It will not contribute to the output and compilation errors may occur as a result.* - [**CS9154**](#signature-mismatch): *Intercepting a call to `M` with interceptor `V`, but the signatures do not match.* - [**CS9158**](#signature-mismatch): *Nullability of reference types in return type doesn't match interceptable method.* - [**CS9159**](#signature-mismatch): *Nullability of reference types in type of parameter doesn't match interceptable method.* From f9176adca1e7ef182935cbca7f06bb4768159cb3 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 21 Oct 2025 08:04:51 -0400 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Meaghan Osagie (Lewis) --- .../compiler-messages/array-declaration-errors.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md b/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md index 1d7c1f324d95f..211d07ae2b64f 100644 --- a/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md +++ b/docs/csharp/language-reference/compiler-messages/array-declaration-errors.md @@ -120,7 +120,7 @@ That's by design. The text closely matches the text of the compiler error / warn - [**CS9188**](#invalid-collection-builder): *Type has a CollectionBuilderAttribute but no element type.* - [**CS9203**](#invalid-collection-initializer): *A collection expression of this type cannot be used in this context because it may be exposed outside of the current scope.* - [**CS9210**](#invalid-collection-initializer): *This version of cannot be used with collection expressions.* -- [**CS9212**](#invalid-collection-initializer): *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'* +- [**CS9212**](#invalid-collection-initializer): *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'.* - [**CS9213**](#invalid-collection-initializer): *Collection expression target 'type' has no element type.* - [**CS9214**](#invalid-collection-initializer): *Collection expression type must have an applicable constructor that can be called with no arguments.* - [**CS9215**](#invalid-collection-initializer): *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.* @@ -156,7 +156,7 @@ The following errors indicate that the code generated by the compiler for a coll - **CS9176**: *There is no target type for the collection literal.* - **CS9203**: *A collection expression of this type cannot be used in this context because it may be exposed outside of the current scope.* - **CS9210**: *This version of cannot be used with collection expressions.* -- **CS9212**: *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'* +- **CS9212**: *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'.* - **CS9213**: *Collection expression target 'type' has no element type.* - **CS9214**: *Collection expression type must have an applicable constructor that can be called with no arguments.* - **CS9215**: *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.* From 35134472d51c0e326b3d694ff28ccf062cb90bd2 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 21 Oct 2025 08:05:19 -0400 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Meaghan Osagie (Lewis) --- .../compiler-messages/ref-modifiers-errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md index 3e472462c0703..911d2458a90b8 100644 --- a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md +++ b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md @@ -211,7 +211,7 @@ The following warnings are generated when reference variables are used incorrect - [**CS9198**](#reference-variable-restrictions): *Reference kind modifier of parameter doesn't match the corresponding parameter in target.* - [**CS9200**](#reference-variable-restrictions): *A default value is specified for `ref readonly` parameter, but `ref readonly` should be used only for references. Consider declaring the parameter as `in`.* - [**CS9201**](#reference-variable-restrictions): *Ref field should be ref-assigned before use.* -- [**CS9205**](#incorrect-syntax): *Expected interpolated string* +- [**CS9205**](#incorrect-syntax): *Expected interpolated string.* - [**CS9265**](#reference-variable-restrictions): *Field is never ref-assigned to, and will always have its default value (null reference)* These errors and warnings follow these themes: From 07bf2a7beced64798b4d221a79cbb382130620ef Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Tue, 21 Oct 2025 08:05:29 -0400 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Meaghan Osagie (Lewis) --- .../compiler-messages/ref-modifiers-errors.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md index 911d2458a90b8..448ec0708f014 100644 --- a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md +++ b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md @@ -231,7 +231,7 @@ These errors indicate that you're using incorrect syntax regarding reference var - **CS8373**: *The left-hand side of a `ref` assignment must be a ref variable.* - **CS8388**: *An `out` variable cannot be declared as a ref local.* - **CS9190**: *`readonly` modifier must be specified after `ref`.* -- **CS9205**: *Expected interpolated string* +- **CS9205**: *Expected interpolated string.* You can correct the error with one of these changes: