You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/array-declaration-errors.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,11 @@ f1_keywords:
37
37
- "CS9208"
38
38
- "CS9209"
39
39
- "CS9210"
40
+
- "CS9212"
41
+
- "CS9213"
42
+
- "CS9214"
43
+
- "CS9215"
44
+
- "CS9222"
40
45
helpviewer_keywords:
41
46
- "CS0022"
42
47
- "CS0178"
@@ -73,6 +78,11 @@ helpviewer_keywords:
73
78
- "CS9208"
74
79
- "CS9209"
75
80
- "CS9210"
81
+
- "CS9212"
82
+
- "CS9213"
83
+
- "CS9214"
84
+
- "CS9215"
85
+
- "CS9222"
76
86
ms.date: 11/02/2023
77
87
---
78
88
# 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
110
120
-[**CS9188**](#invalid-collection-builder): *Type has a CollectionBuilderAttribute but no element type.*
111
121
-[**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.*
112
122
-[**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'.*
113
128
114
129
In addition, the following warnings are covered in this article:
115
130
@@ -141,6 +156,11 @@ The following errors indicate that the code generated by the compiler for a coll
141
156
-**CS9176**: *There is no target type for the collection literal.*
142
157
-**CS9203**: *A collection expression of this type cannot be used in this context because it may be exposed outside of the current scope.*
143
158
-**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'.*
144
164
145
165
The compiler might also generate the following warning:
146
166
@@ -159,6 +179,11 @@ The errors all indicate that the code generated by the compiler for a collection
159
179
- 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.
160
180
- A `ref struct` type, like <xref:System.Span%601?displayProperty=nameWithType> can't be initialized with a collection expression that may violate ref safety.
161
181
- 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.
162
187
163
188
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.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/inline-array-errors.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
title: Resolve errors related to inline arrays
3
3
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.
4
4
f1_keywords:
5
+
- "CS9125"
5
6
- "CS9164"
6
7
- "CS9165"
7
8
- "CS9166"
@@ -18,6 +19,7 @@ f1_keywords:
18
19
- "CS9189"
19
20
- "CS9259"
20
21
helpviewer_keywords:
22
+
- "CS9125"
21
23
- "CS9164"
22
24
- "CS9165"
23
25
- "CS9166"
@@ -42,6 +44,7 @@ This article covers the following compiler errors and warnings:
42
44
<!-- The text in this list generates issues for Acrolinx, because they don't use contractions.
43
45
That's by design. The text closely matches the text of the compiler error / warning for SEO purposes.
44
46
-->
47
+
-[**CS9125**](#inline-array-declaration): *Attribute parameter 'SizeConst' must be specified.*
45
48
-[**CS9164**](#conversions-to-span): *Cannot convert expression to `Span<T>` because it is not an assignable variable*
46
49
-[**CS9165**](#conversions-to-span): *Cannot convert expression to `ReadOnlySpan<T>` because it may not be passed or returned by reference*
47
50
-[**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
62
65
63
66
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:
64
67
68
+
-**CS9125**: *Attribute parameter 'SizeConst' must be specified.*
65
69
-**CS9167**: *Inline array length must be greater than 0.*
66
70
-**CS9168**: *Inline array struct must not have explicit layout.*
67
71
-**CS9169**: *Inline array struct must declare one and only one instance field which must not be a ref field.*
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/lambda-expression-errors.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ f1_keywords:
18
18
- "CS9098"# ERR_ImplicitlyTypedDefaultParameter: Implicitly typed lambda parameter '{0}' cannot have a default value.
19
19
- "CS9099"# WRN_OptionalParamValueMismatch: The default parameter value does not match in the target delegate type.
20
20
- "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.
21
22
helpviewer_keywords:
22
23
- "CS0748"
23
24
- "CS0835"
@@ -35,6 +36,7 @@ helpviewer_keywords:
35
36
- "CS9098"
36
37
- "CS9099"
37
38
- "CS9100"
39
+
- "CS9236"
38
40
ms.date: 05/04/2023
39
41
---
40
42
# 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
64
66
-[**CS9099**](#lambda-expression-delegate-type): *The default parameter value does not match in the target delegate type.*
65
67
-[**CS9100**](#lambda-expression-delegate-type): *Parameter has params modifier in lambda but not in target delegate type.*
66
68
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
+
67
73
## Syntax limitations in lambda expressions
68
74
69
75
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,12 @@ In addition, interpolated string handler types are ignored when applied to a lam
90
96
91
97
-**CS8971**: *InterpolatedStringHandlerArgument has no effect when applied to lambda parameters and will be ignored at the call site.*
92
98
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.
104
+
93
105
## Lambda expression parameters and returns
94
106
95
107
These errors indicate a problem with a parameter declaration:
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,7 @@ f1_keywords:
66
66
- "CS9199"
67
67
- "CS9200"
68
68
- "CS9201"
69
+
- "CS9205"
69
70
- "CS9265"
70
71
helpviewer_keywords:
71
72
- "CS0192"
@@ -132,6 +133,7 @@ helpviewer_keywords:
132
133
- "CS9199"
133
134
- "CS9200"
134
135
- "CS9201"
136
+
- "CS9205"
135
137
- "CS9265"
136
138
ms.date: 11/06/2024
137
139
---
@@ -209,6 +211,7 @@ The following warnings are generated when reference variables are used incorrect
209
211
-[**CS9198**](#reference-variable-restrictions): *Reference kind modifier of parameter doesn't match the corresponding parameter in target.*
210
212
-[**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`.*
211
213
-[**CS9201**](#reference-variable-restrictions): *Ref field should be ref-assigned before use.*
-[**CS9265**](#reference-variable-restrictions): *Field is never ref-assigned to, and will always have its default value (null reference)*
213
216
214
217
These errors and warnings follow these themes:
@@ -228,12 +231,14 @@ These errors indicate that you're using incorrect syntax regarding reference var
228
231
-**CS8373**: *The left-hand side of a `ref` assignment must be a ref variable.*
229
232
-**CS8388**: *An `out` variable cannot be declared as a ref local.*
230
233
-**CS9190**: *`readonly` modifier must be specified after `ref`.*
234
+
-**CS9205**: *Expected interpolated string.*
231
235
232
236
You can correct the error with one of these changes:
233
237
234
238
- 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).
235
239
- The parameter modifier `ref readonly` must be in that order. `readonly ref` is not a legal parameter modifier. Switch the order of the words.
236
240
- 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.
0 commit comments