dotnet / dotnet/sdk

CA2208 incorrectly issued for C# 14 extension members

Open
#51,887 0 comments 3 reactions 0 assignees View on GitHub
Area-Microsoft.CodeAnalysis.NetAnalyzers untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

Use the `nameof` expression on the extension parameter in a C# 14 extension member and CA2208 is emited. It shouldn't be.

### To Reproduce

Try this code:

```csharp
public static class ExampleExtensions
{
extension(IEnumerable sequence)
{
public IEnumerable Sample(int frequency,
[CallerArgumentExpression(nameof(sequence))] string? message = null)
{
if (sequence.Count() < frequency)
throw new ArgumentException($"Expression doesn't have enough elements: {message}", nameof(sequence));
int i = 0;
foreach (T item in sequence)
{
if (i++ % frequency == 0)
yield return item;
}
}
}
}
```

The line that throws a new `ArgumentException` emits CS2208. The explanation is that `sequence` isn't a parameter. But it is, even though it's on the `extension` node.

### Exceptions (if any)

### Further technical details

I reproduced on the VS 2026 G.A. November release.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.