Skip to content

Commit 4589ff0

Browse files
committed
Move errors to correct theme.
1 parent 251189c commit 4589ff0

File tree

8 files changed

+88
-84
lines changed

8 files changed

+88
-84
lines changed

docs/csharp/language-reference/compiler-messages/array-declaration-errors.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ f1_keywords:
3737
- "CS9208"
3838
- "CS9209"
3939
- "CS9210"
40+
- "CS9212"
41+
- "CS9213"
42+
- "CS9214"
43+
- "CS9215"
44+
- "CS9222"
4045
helpviewer_keywords:
4146
- "CS0022"
4247
- "CS0178"
@@ -73,6 +78,11 @@ helpviewer_keywords:
7378
- "CS9208"
7479
- "CS9209"
7580
- "CS9210"
81+
- "CS9212"
82+
- "CS9213"
83+
- "CS9214"
84+
- "CS9215"
85+
- "CS9222"
7686
ms.date: 11/02/2023
7787
---
7888
# 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
110120
- [**CS9188**](#invalid-collection-builder): *Type has a CollectionBuilderAttribute but no element type.*
111121
- [**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.*
112122
- [**CS9210**](#invalid-collection-initializer): *This version of <xref:System.Collections.Immutable.ImmutableArray%601?displayProperty=nameWithType>cannot be used with collection expressions.*
123+
- [**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'*
124+
- [**CS9213**](#invalid-collection-initializer): *Collection expression target 'type' has no element type.*
125+
- [**CS9214**](#invalid-collection-initializer): *Collection expression type must have an applicable constructor that can be called with no arguments.*
126+
- [**CS9215**](#invalid-collection-initializer): *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.*
127+
- [**CS9222**](#invalid-collection-initializer): *Collection initializer results in an infinite chain of instantiations of collection 'type'.*
113128

114129
In addition, the following warnings are covered in this article:
115130

@@ -141,6 +156,11 @@ The following errors indicate that the code generated by the compiler for a coll
141156
- **CS9176**: *There is no target type for the collection literal.*
142157
- **CS9203**: *A collection expression of this type cannot be used in this context because it may be exposed outside of the current scope.*
143158
- **CS9210**: *This version of <xref:System.Collections.Immutable.ImmutableArray%601?displayProperty=nameWithType>cannot be used with collection expressions.*
159+
- **CS9212**: *Spread operator '`..`' cannot operate on variables of type 'type' because 'type' does not contain a public instance or extension definition for 'member'*
160+
- **CS9213**: *Collection expression target 'type' has no element type.*
161+
- **CS9214**: *Collection expression type must have an applicable constructor that can be called with no arguments.*
162+
- **CS9215**: *Collection expression type 'type' must have an instance or extension method 'Add' that can be called with a single argument.*
163+
- **CS9222**: *Collection initializer results in an infinite chain of instantiations of collection 'type'.*
144164

145165
The compiler might also generate the following warning:
146166

@@ -159,6 +179,11 @@ The errors all indicate that the code generated by the compiler for a collection
159179
- 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.
160180
- A `ref struct` type, like <xref:System.Span%601?displayProperty=nameWithType> can't be initialized with a collection expression that may violate ref safety.
161181
- A collection expression can't correctly initialize an <xref:System.Collections.Immutable.ImmutableArray%601?displayProperty=nameWithType> using the current version. Use a different version of the runtime, or change the initialization expression.
182+
- 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.
183+
- **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.
184+
- **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.
185+
- **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.
186+
- **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.
162187

163188
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.
164189

docs/csharp/language-reference/compiler-messages/inline-array-errors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Resolve errors related to inline arrays
33
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.
44
f1_keywords:
5+
- "CS9125"
56
- "CS9164"
67
- "CS9165"
78
- "CS9166"
@@ -18,6 +19,7 @@ f1_keywords:
1819
- "CS9189"
1920
- "CS9259"
2021
helpviewer_keywords:
22+
- "CS9125"
2123
- "CS9164"
2224
- "CS9165"
2325
- "CS9166"
@@ -42,6 +44,7 @@ This article covers the following compiler errors and warnings:
4244
<!-- The text in this list generates issues for Acrolinx, because they don't use contractions.
4345
That's by design. The text closely matches the text of the compiler error / warning for SEO purposes.
4446
-->
47+
- [**CS9125**](#inline-array-declaration): *Attribute parameter 'SizeConst' must be specified.*
4548
- [**CS9164**](#conversions-to-span): *Cannot convert expression to `Span<T>` because it is not an assignable variable*
4649
- [**CS9165**](#conversions-to-span): *Cannot convert expression to `ReadOnlySpan<T>` because it may not be passed or returned by reference*
4750
- [**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
6265

6366
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:
6467

68+
- **CS9125**: *Attribute parameter 'SizeConst' must be specified.*
6569
- **CS9167**: *Inline array length must be greater than 0.*
6670
- **CS9168**: *Inline array struct must not have explicit layout.*
6771
- **CS9169**: *Inline array struct must declare one and only one instance field which must not be a ref field.*

docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ f1_keywords:
1818
- "CS9098" # ERR_ImplicitlyTypedDefaultParameter: Implicitly typed lambda parameter '{0}' cannot have a default value.
1919
- "CS9099" # WRN_OptionalParamValueMismatch: The default parameter value does not match in the target delegate type.
2020
- "CS9100" # WRN_ParamsArrayInLambdaOnly: Parameter has params modifier in lambda but not in target delegate type.
21+
- "CS9236" # INF_TooManyBoundLambdas: Compiling requires binding the lambda expression at least {0} times.
2122
helpviewer_keywords:
2223
- "CS0748"
2324
- "CS0835"
@@ -35,6 +36,7 @@ helpviewer_keywords:
3536
- "CS9098"
3637
- "CS9099"
3738
- "CS9100"
39+
- "CS9236"
3840
ms.date: 05/04/2023
3941
---
4042
# 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
6466
- [**CS9099**](#lambda-expression-delegate-type): *The default parameter value does not match in the target delegate type.*
6567
- [**CS9100**](#lambda-expression-delegate-type): *Parameter has params modifier in lambda but not in target delegate type.*
6668

69+
The compiler also produces the following *informational* message:
70+
71+
- [**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.*
72+
6773
## Syntax limitations in lambda expressions
6874

6975
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
9096

9197
- **CS8971**: *InterpolatedStringHandlerArgument has no effect when applied to lambda parameters and will be ignored at the call site.*
9298

99+
Certain expressions cause the compiler to emit the following informational warning:
100+
101+
- **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.*
102+
103+
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.
93104
## Lambda expression parameters and returns
94105

95106
These errors indicate a problem with a parameter declaration:

docs/csharp/language-reference/compiler-messages/misc-12-errors.md

Lines changed: 0 additions & 79 deletions
This file was deleted.

docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ f1_keywords:
6666
- "CS9199"
6767
- "CS9200"
6868
- "CS9201"
69+
- "CS9205"
6970
- "CS9265"
7071
helpviewer_keywords:
7172
- "CS0192"
@@ -132,6 +133,7 @@ helpviewer_keywords:
132133
- "CS9199"
133134
- "CS9200"
134135
- "CS9201"
136+
- "CS9205"
135137
- "CS9265"
136138
ms.date: 11/06/2024
137139
---
@@ -209,6 +211,7 @@ The following warnings are generated when reference variables are used incorrect
209211
- [**CS9198**](#reference-variable-restrictions): *Reference kind modifier of parameter doesn't match the corresponding parameter in target.*
210212
- [**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`.*
211213
- [**CS9201**](#reference-variable-restrictions): *Ref field should be ref-assigned before use.*
214+
- [**CS9205**](#incorrect-syntax): *Expected interpolated string*
212215
- [**CS9265**](#reference-variable-restrictions): *Field is never ref-assigned to, and will always have its default value (null reference)*
213216

214217
These errors and warnings follow these themes:
@@ -228,12 +231,14 @@ These errors indicate that you're using incorrect syntax regarding reference var
228231
- **CS8373**: *The left-hand side of a `ref` assignment must be a ref variable.*
229232
- **CS8388**: *An `out` variable cannot be declared as a ref local.*
230233
- **CS9190**: *`readonly` modifier must be specified after `ref`.*
234+
- **CS9205**: *Expected interpolated string*
231235

232236
You can correct the error with one of these changes:
233237

234238
- 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).
235239
- The parameter modifier `ref readonly` must be in that order. `readonly ref` is not a legal parameter modifier. Switch the order of the words.
236240
- A local variable can't be declared as `out`. To declare a local reference variable, use `ref`.
241+
- An `out` argument can't be an interpolated string.
237242

238243
## Reference variable restrictions
239244

docs/csharp/language-reference/compiler-messages/source-generator-errors.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ f1_keywords:
3131
- "CS9178"
3232
- "CS9206"
3333
- "CS9207"
34+
- "CS9231"
35+
- "CS9232"
36+
- "CS9233"
37+
- "CS9234"
38+
- "CS9235"
3439
- "CS9270"
3540
helpviewer_keywords:
3641
- "CS9137"
@@ -62,6 +67,11 @@ helpviewer_keywords:
6267
- "CS9178"
6368
- "CS9206"
6469
- "CS9207"
70+
- "CS9231"
71+
- "CS9232"
72+
- "CS9233"
73+
- "CS9234"
74+
- "CS9235"
6575
- "CS9270"
6676
ms.date: 05/23/2025
6777
---
@@ -95,6 +105,11 @@ The following errors are generated when source generators or interceptors are lo
95105
- [**CS9178**](#signature-mismatch): *Method must be non-generic to match*
96106
- [**CS9206**](#other-failures): *An interceptor cannot be declared in the global namespace.*
97107
- [**CS9207**](#other-failures): *Cannot intercept because method is not an invocation of an ordinary member method.*
108+
- [**CS9231**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute is not in the correct format.*
109+
- [**CS9232**](#interceptslocationattribute-errors): *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.*
110+
- [**CS9233**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.*
111+
- [**CS9234**](#interceptslocationattribute-errors): *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.*
112+
- [**CS9235**](#interceptslocationattribute-errors): *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.*
98113

99114
The following warnings are generated when source generators or interceptors are loaded during a compilation:
100115

@@ -160,6 +175,24 @@ Interceptors require a source mapping that maps the interceptable method and the
160175

161176
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).
162177

178+
## InterceptsLocationAttribute errors
179+
180+
The following errors indicate issues with the `InterceptsLocationAttribute` format or the data provided to it:
181+
182+
- **CS9231**: *The data argument to InterceptsLocationAttribute is not in the correct format.*
183+
- **CS9232**: *Version 'version' of the interceptors format is not supported. The latest supported version is '1'.*
184+
- **CS9233**: *Cannot intercept a call in file 'file' because it is duplicated elsewhere in the compilation.*
185+
- **CS9234**: *Cannot intercept a call in file 'file' because a matching file was not found in the compilation.*
186+
- **CS9235**: *The data argument to InterceptsLocationAttribute refers to an invalid position in file 'file'.*
187+
188+
These errors occur when the `InterceptsLocationAttribute` contains invalid data:
189+
190+
- **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.
191+
- **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.
192+
- **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.
193+
- **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.
194+
- **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.
195+
163196
## Other failures
164197

165198
These errors indicate other limitations for interceptors:

0 commit comments

Comments
 (0)