sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Getting the error CS0103 The name 'paramName' does not exist in the current context in terminal but not in IDE

Open livan3li opened this issue 1 year ago • 1 comments

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. image

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

  1. 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

livan3li avatar Mar 03 '24 09:03 livan3li

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.

KalleOlaviNiemitalo avatar Mar 03 '24 10:03 KalleOlaviNiemitalo

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.

marcpopMSFT avatar Apr 02 '24 17:04 marcpopMSFT