Skip to content

Commit 4dbcb04

Browse files
committed
Add placeholders for all new extension errors
Add the description and fixes for all new extension errors.
1 parent ddd980b commit 4dbcb04

File tree

4 files changed

+109
-43
lines changed

4 files changed

+109
-43
lines changed

docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ f1_keywords:
4747
- "CS9170"
4848
- "CS9175"
4949
- "CS9226"
50+
- "CS9296"
51+
- "CS9307"
5052
helpviewer_keywords:
5153
- "CS0765"
5254
- "CS0831"
@@ -94,7 +96,9 @@ helpviewer_keywords:
9496
- "CS9170"
9597
- "CS9175"
9698
- "CS9226"
97-
ms.date: 09/06/2023
99+
- "CS9296"
100+
- "CS9307"
101+
ms.date: 05/27/2025
98102
---
99103
# Resolve errors and warnings generated from expressions prohibited in expression trees
100104

@@ -149,6 +153,8 @@ That's by design. The text closely matches the text of the compiler error / warn
149153
- **CS9170** - *An expression tree may not contain an inline array access or conversion.*
150154
- **CS9175** - *An expression tree may not contain a collection expression.*
151155
- **CS9226** - *An expression tree may not contain an expanded form of non-array params collection parameter.*
156+
- **CS9296** - *An expression tree may not contain an extension property access*.
157+
- **CS9307** - *An expression tree may not contain a named argument specification out of position*.
152158

153159
## Expression tree restrictions
154160

@@ -184,6 +190,7 @@ The following expressions are prohibited:
184190

185191
Other restrictions are:
186192

193+
- Extension properties can't be accessed as extensions.
187194
- Attributes can't be applied to the lambda expression, its parameters or return.
188195
- The lambda expression must be convertible to a type derived from <xref:System.Linq.Expressions.Expression?displayProperty=fullName> whose type parameter is a delegate type.
189196
- [named and optional parameters](../../programming-guide/classes-and-structs/named-and-optional-arguments.md) are restricted. The expression can't call a method specifying named arguments, and it can't use the default value of an optional parameter.

docs/csharp/language-reference/compiler-messages/extension-declarations.md

Lines changed: 91 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ f1_keywords:
1313
- "CS1110"
1414
- "CS1112"
1515
- "CS1113"
16+
- "CS9281"
17+
- "CS9282"
18+
- "CS9283"
19+
- "CS9284"
20+
- "CS9285"
21+
- "CS9287"
22+
- "CS9288"
23+
- "CS9289"
24+
- "CS9290"
25+
- "CS9292"
26+
- "CS9293"
27+
- "CS9295"
28+
- "CS9300"
29+
- "CS9301"
30+
- "CS9302"
31+
- "CS9303"
32+
- "CS9304"
33+
- "CS9305"
1634
helpviewer_keywords:
1735
- "CS1100"
1836
- "CS1101"
@@ -24,31 +42,66 @@ helpviewer_keywords:
2442
- "CS1110"
2543
- "CS1112"
2644
- "CS1113"
45+
- "CS9281"
46+
- "CS9282"
47+
- "CS9283"
48+
- "CS9284"
49+
- "CS9285"
50+
- "CS9287"
51+
- "CS9288"
52+
- "CS9289"
53+
- "CS9290"
54+
- "CS9291"
55+
- "CS9292"
56+
- "CS9293"
57+
- "CS9294"
58+
- "CS9295"
59+
- "CS9300"
60+
- "CS9301"
61+
- "CS9302"
62+
- "CS9303"
63+
- "CS9304"
64+
- "CS9305"
2765
---
2866
# Errors and warnings related to extension methods declared with `this` parameters or `extension` blocks
2967

68+
- **CS1100**: *Method has a parameter modifier '`this`' which is not on the first parameter*
69+
- **CS1101**: *The parameter modifier '`ref`' cannot be used with '`this`'.*
70+
- **CS1102**: *The parameter modifier '`out`' cannot be used with '`this`'.*
71+
- **CS1103**: *The first parameter of an extension method cannot be of a pointer type.*
72+
- **CS1105**: *Extension methods must be static.*
73+
- **CS1106**: *Extension methods must be defined in a non generic static class.*
74+
- **CS1109**: *Extension Methods must be defined on top level static classes, 'name' is a nested class.*
75+
- **CS1110**: *Cannot define a new extension because the compiler required type <xref:System.Runtime.CompilerServices.ExtensionAttribute> cannot be found. Are you missing a reference to System.Core.dll?*
3076
- **CS1112**: *Do not use '<xref:System.Runtime.CompilerServices.ExtensionAttribute>'. Use the '`this`' keyword instead.*
77+
- **CS1113**: *Extension method defined on a value type cannot be used to create delegates.*
78+
- **CS9281**: *Extension declarations may not have a name.*
79+
- **CS9282**: *Extension declarations can include only methods or properties.*
80+
- **CS9283**: *Extensions must be declared in a top-level, non-generic, static class.*
81+
- **CS9284**: *The receiver parameter of an extension cannot have a default value.*
82+
- **CS9285**: *An extension container can have only one receiver parameter.*
83+
- **CS9287**: *A receiver parameter cannot have the same name as an extension container type parameter.*
84+
- **CS9288**: *A parameter, local variable, or local function cannot have the same name as an extension container type parameter.*
85+
- **CS9289**: *Member type parameter has the same name as an extension container type parameter.*
86+
- **CS9290**: *A parameter, local variable, or local function cannot have the same name as an extension parameter.*
87+
- **CS9291**: *'`value`': an automatically-generated parameter name conflicts with an extension parameter name.*
88+
- **CS9292**: *A type parameter has the same name as an extension parameter.*
89+
- **CS9293**: *Cannot use an extension parameter in this context.*
90+
- **CS9294**: *'`value`': an automatically-generated parameter name conflicts with an extension type parameter name.*
91+
- **CS9295**: *The extended type must reference all the type parameters declared by the extension, but a type parameter is not referenced.*
92+
- **CS9300**: *The '`ref`' receiver parameter of an extension block must be a value type or a generic type constrained to struct.*
93+
- **CS9301**: *The '`in`' or '`ref readonly`' receiver parameter of extension must be a concrete (non-generic) value type.*
94+
- **CS9302**: *new protected member declared in an extension block.*
95+
- **CS9303**: *Cannot declare instance members in an extension block with an unnamed receiver parameter.*
96+
- **CS9304**: *Cannot declare init-only accessors in an extension block.*
97+
- **CS9305**: *Cannot use modifiers on the unnamed receiver parameter of extension block.*
3198

32-
## CS1112
33-
34-
This error is generated when the <xref:System.Runtime.CompilerServices.ExtensionAttribute> is used on a non-static class that contains extension methods. If this attribute is used on a static class, another error, such as CS0708: "Cannot declare instance members in a static class," might occur.
35-
36-
In C#, extension methods must be defined in a static class and the first parameter of the method is modified with the `this` keyword. Do not use the attribute at all in the source code. For more information, see [Extension Methods](../../../programming-guide/classes-and-structs/extension-methods.md). To correct this error remove the attribute and apply the `this` modifier to the first parameter of the method. The following example generates CS1112:
37-
38-
```csharp
39-
// cs1112.cs
40-
[System.Runtime.CompilerServices.ExtensionAttribute] // CS1112
41-
public class Extensions
42-
{
43-
public bool A(bool b) { return b; }
44-
}
45-
46-
class A { }
47-
```
4899

49100
## Compiler Error CS1100
50101

51-
Method 'name' has a parameter modifier 'this' which is not on the first parameter. The `this` modifier is allowed only on the first parameter of a method, which indicates to the compiler that the method is an extension method. To correct this error remove the `this` modifier from all except the first parameter of the method. The following code generates CS1100 because a `this` parameter is modifying the second parameter:
102+
Method 'name' has a parameter modifier 'this' which is not on the first parameter.
103+
104+
The `this` modifier is allowed only on the first parameter of a method, which indicates to the compiler that the method is an extension method. To correct this error remove the `this` modifier from all except the first parameter of the method. The following code generates CS1100 because a `this` parameter is modifying the second parameter:
52105

53106
```csharp
54107
// cs1100.cs
@@ -101,7 +154,7 @@ public static class Extensions
101154

102155
## Compiler Error CS1103
103156

104-
The first parameter of an extension method cannot be of type 'type'.
157+
The first parameter of an extension method cannot be of type.
105158

106159
The first parameter of an extension method cannot be a pointer type. The following example generates CS1103:
107160

@@ -179,7 +232,7 @@ static class Out
179232

180233
## Compiler Error CS1110
181234

182-
Cannot use 'this' modifier on first parameter of method declaration without a reference to System.Core.dll. Add a reference to System.Core.dll or remove 'this' modifier from the method declaration.
235+
Cannot define a new extension because the compiler required type '{0}' cannot be found. Are you missing a reference to System.Core.dll?
183236

184237
Extension methods are supported on version 3.5 and later of .NET Framework. Extension methods generate metadata which marks the method with an attribute. The attribute class is in system.core.dll. To correct this error, as the message states, add a reference to System.Core.dll or remove the `this` modifier from the method declaration. The following example generates CS1110 if the file is not compiled with a reference to System.Core.dll:
185238

@@ -193,6 +246,25 @@ public static class Extensions
193246
}
194247
```
195248

249+
## CS1112
250+
251+
Do not use 'System.Runtime.CompilerServices.ExtensionAttribute'. Use the 'this' keyword instead.
252+
253+
This error is generated when the <xref:System.Runtime.CompilerServices.ExtensionAttribute> is used on a non-static class that contains extension methods. If this attribute is used on a static class, another error, such as CS0708: "Cannot declare instance members in a static class," might occur.
254+
255+
In C#, extension methods must be defined in a static class and the first parameter of the method is modified with the `this` keyword. Do not use the attribute at all in the source code. For more information, see [Extension Methods](../../../programming-guide/classes-and-structs/extension-methods.md). To correct this error remove the attribute and apply the `this` modifier to the first parameter of the method. The following example generates CS1112:
256+
257+
```csharp
258+
// cs1112.cs
259+
[System.Runtime.CompilerServices.ExtensionAttribute] // CS1112
260+
public class Extensions
261+
{
262+
public bool A(bool b) { return b; }
263+
}
264+
265+
class A { }
266+
```
267+
196268
## Compiler Error CS1113
197269

198270
Extension methods 'name' defined on value type 'name' cannot be used to create delegates.

docs/csharp/language-reference/toc.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,10 @@ items:
505505
CS1622, CS1624, CS1625, CS1626, CS1627, CS1629, CS1631, CS1637, CS4013, CS8154, CS8176, CS9237, CS9238, CS9239
506506
- name: Extension declarations
507507
href: ./compiler-messages/extension-declarations.md
508-
displayName: CS1100, CS1101, CS1102, CS1103, CS1105, CS1106, CS1109, CS1110, CS1113, CS1112
508+
displayName: >
509+
CS1100, CS1101, CS1102, CS1103, CS1105, CS1106, CS1109, CS1110, CS1113, CS1112, CS1100, CS1101, CS1102, CS1103
510+
CS1105, CS1106, CS1109, CS1110, CS1112, CS1113, CS9281, CS9282, CS9283, CS9284, CS9285, CS9287, CS9288, CS9289,
511+
CS9290, CS9292, CS9293, CS9295, CS9300, CS9301, CS9302, CS9303, CS9304, CS9305
509512
- name: Partial declarations
510513
href: ./compiler-messages/partial-declarations.md
511514
displayName: >

docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -622,39 +622,23 @@ f1_keywords:
622622
- "CS9235"
623623
- "CS9236"
624624
# C# 14 errors begin here
625-
- "CS9281"
626-
- "CS9282"
627-
- "CS9283"
628-
- "CS9284"
629-
- "CS9285"
625+
## "Are you missing a using or assembly reference?"
630626
- "CS9286"
631-
- "CS9287"
632-
- "CS9288"
633-
- "CS9289"
634-
- "CS9290"
635-
- "CS9291"
636-
- "CS9292"
637-
- "CS9293"
638-
- "CS9294"
639-
- "CS9295"
640-
- "CS9296"
627+
## Shebang
641628
- "CS9297"
642629
- "CS9298"
643630
- "CS9299"
644-
- "CS9300"
645-
- "CS9301"
646-
- "CS9302"
647-
- "CS9303"
648-
- "CS9304"
649-
- "CS9305"
631+
## using `extension` as type name. (valid identifiers).
650632
- "CS9306"
651-
- "CS9307"
633+
## User defined operators
652634
- "CS9308"
653635
- "CS9310"
654636
- "CS9311"
655637
- "CS9312"
656638
- "CS9313"
639+
## Shebang
657640
- "CS9314"
641+
## Strings in the data section:
658642
- "CS9315"
659643
helpviewer_keywords:
660644
- "errors [C#], additional information"

0 commit comments

Comments
 (0)