Getting the error CS0103 The name 'paramName' does not exist in the current context in terminal but not in IDE
Describe the bug
If I try to build project that have the following code in the project I get
error CS0103: The name 'paramName' does not exist in the current context
in the terminal.
[Route($"{nameof(paramName)}")] public async Task<IActionResult<bool>> GetValue(string paramName) { // some code... }
But if I try to build same code/project through solution explorer in vs code like in the following picture I do not get any error.
And also I do not get any error from VS Code telling the above error. I get only if I run dotnet build command in the terminal.
I don't know if this error is caused by C# Extension or dotnet SDK. I wanted to post bug here.
To Reproduce
- Try to build above sample code two different ways. a. By Solution Explorer like in the image b. By dotnet build command in terminal
Further technical details
- DOTNET VERSION: 6.0.418
- C# Extension Version: 2.19.13
- C# Dev Kit Version: 1.3.10
- VSCode Version: 1.87.0
- OS: Linux Debian.12-x64
That's a C# 11 feature; see https://github.com/dotnet/csharplang/issues/373 and What's new in C# 11. According to C# language versioning, "C# 11 is supported only on .NET 7 and newer versions." So it's by design that you get an error on .NET SDK 6.0.418. But I wonder why C# Extension and C# Dev Kit allow this code.
Per Kalle, looks like this is a new feature. Feel free to file a devkit issue if you believe it should be flagged in the UI rather than in the build. By design for the sdk though.