ARTICLE AD BOX
I'm experimenting with the new C# 14 extension syntax in .NET 10, and I hit an error I can't find documentation for:
public static class Foo { extension(int bar) { public static int Baz() => bar % 2; } }The compiler reports, under the variable baz right before the modulo operator:
CS9293: Cannot use an extension parameter in this context.I expected bar to be usable inside Baz, but it seems disallowed. There's no documentation for CS9293, and I couldn't find any references online.
Question:
Why does this error occur, and what's the correct way to use extension parameters in this scenario?
7,5792 gold badges16 silver badges32 bronze badges
1,0033 gold badges8 silver badges40 bronze badges
3
The error occurs because extension parameters can only be used inside non‑static methods of the extension block. Static methods don't capture the extension parameter, so the compiler reports CS9293.
To fix it, remove the static modifier:
public int Baz() => bar % 2; // <-- removed 'static'1,0033 gold badges8 silver badges40 bronze badges
Explore related questions
See similar questions with these tags.
