-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
untriagedRequest triage from a team memberRequest triage from a team member
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:
public static class ExampleExtensions
{
extension<T>(IEnumerable<T> sequence)
{
public IEnumerable<T> 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.
Metadata
Metadata
Assignees
Labels
untriagedRequest triage from a team memberRequest triage from a team member