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?

Ivan Petrov's user avatar

Ivan Petrov

7,5792 gold badges16 silver badges32 bronze badges

winscripter's user avatar

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'

winscripter's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.