CS0027: (undocumented) new cause
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 19h 10m
- Merged PRs (30d)
- 268
Description
### Type of issue
Missing information
### Description
V14 introduced a new cause for this error.
I'm writing text for the formal Ecma spec for the V14 feature, "Extension members," and stumbled on this in one of my tests. Consider the following code:
```csharp
public static class Ex4
{
public static void MX1(this int p) { int z = p; } // OK: old-style extension method
extension(int q)
{
public static void MX2(this int p) { int z = p; } // CS0027 old-style extension method inside an extension block
public void MX3() { int z = q; } // OK: new-style extension method
}
}
```
By having a first parameter with the `this` modifier, method `MX1` is recognized as an (old-style) extension method. OK! The correct way to rewrite that declaration using the V14 (new-style) is like `MX3`.
Writing it like `MX2` generates CS0027. So although this is a method declaration, it is an old-style extension method inside a new-style extension block, and apparently that is not permitted.
### Page URL
https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0027?f1url=%3FappId%3Droslyn%26k%3Dk(CS0027)
### Content source URL
https://github.com/dotnet/docs/blob/main/docs/csharp/misc/cs0027.md
### Document Version Independent Id
ce979e00-3708-b993-0398-fd7995c1f9ae
### Platform Id
084a3d4f-6cf7-cadf-13cc-e94ea4ec83c2
### Article author
@BillWagner
### Metadata
* ID: 0db95a07-85cc-1385-3249-2db88b0dbb34
* PlatformId: 084a3d4f-6cf7-cadf-13cc-e94ea4ec83c2
* Service: **dotnet-csharp**
* Sub-service: **errors-warnings**
[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+ce979e00-3708-b993-0398-fd7995c1f9ae)
---
[Associated WorkItem - 631434](https://dev.azure.com/msft-skilling/Content/_workitems/edit/631434)
Contributor guide
Assessment
This issue has not been assessed yet.