vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Errors in __virtual.cs files in Problems tab

Open BenjaminBrienen opened this issue 5 months ago • 2 comments

Environment data

dotnet --info output:

PS C:\sources\COES> dotnet --info                                                                                                                       
.NET SDK:
 Version:           9.0.102
 Commit:            cb83cd4923
 Workload version:  9.0.100-manifests.71a57da0
 MSBuild version:   17.12.18+ed8c6aec5

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.102\

.NET workloads installed:
 [maui-windows]
   Installation Source: VS 17.12.35707.178
   Manifest Version:    9.0.14/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.14\WorkloadManifest.json
   Install Type:              Msi

 [aspire]
   Installation Source: VS 17.12.35707.178
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools]
   Installation Source: VS 17.12.35707.178
   Manifest Version:    9.0.6/9.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.workload.mono.toolchain.current\9.0.6\WorkloadManifest.json
   Install Type:              Msi

Configured to use loose manifests when installing new manifests.

Host:
  Version:      9.0.6
  Architecture: x64
  Commit:       3875b54e7b

.NET SDKs installed:
  6.0.302 [C:\Program Files\dotnet\sdk]
  6.0.428 [C:\Program Files\dotnet\sdk]
  8.0.314 [C:\Program Files\dotnet\sdk]
  8.0.411 [C:\Program Files\dotnet\sdk]
  9.0.102 [C:\Program Files\dotnet\sdk]
  9.0.205 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

VS Code version:

PS C:\sources\COES> code --version
1.101.0
dfaf44141ea9deb3b4096f7cd6d24e00c147a4b1
x64

C# Extension version:

Name: C# Dev Kit
Id: ms-dotnettools.csdevkit
Description: Official C# extension from Microsoft
Version: 1.20.35
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit

C# logs

C# output window contents:

2025-06-18 10:59:49.886 [info] Starting Spawn .NET server...
2025-06-18 10:59:49.886 [info] Using dotnet resolution provided by ".NET Install Tool".
2025-06-18 10:59:49.889 [info] Starting opening a solution...
2025-06-18 10:59:49.889 [info] Starting processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server...
2025-06-18 10:59:52.568 [info] Using existing .NET runtime at "C:\Program Files\dotnet\dotnet.exe" to load Dev Kit processes.
2025-06-18 10:59:52.740 [info] .NET Sdk found: "C:\Program Files\dotnet\dotnet.exe".
2025-06-18 11:00:02.436 [info] .NET server started and IPC established in 9648ms
2025-06-18 11:00:02.449 [info] Completed Spawn .NET server (12571ms)
2025-06-18 11:00:13.437 [info] Completed processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server (23558ms)
2025-06-18 11:00:13.457 [info] Starting restoring NuGet packages...
2025-06-18 11:00:13.457 [info] Selected configuration: <Default>, active configuration: Debug|x64
2025-06-18 11:00:13.457 [info] Completed opening a solution (23579ms)
2025-06-18 11:00:13.478 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 11:01:07.842 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (54343ms)
2025-06-18 11:01:07.842 [info] Completed restoring NuGet packages (54348ms)
2025-06-18 11:54:19.139 [info] Starting Query for all projects...
2025-06-18 11:54:19.160 [info] Completed Query for all projects (21ms)
2025-06-18 14:41:58.934 [info] C# Dev Kit deactivate() is now executing...
2025-06-18 14:42:03.760 [info] Starting Spawn .NET server...
2025-06-18 14:42:03.760 [info] Using dotnet resolution provided by ".NET Install Tool".
2025-06-18 14:42:03.764 [info] Starting opening a solution...
2025-06-18 14:42:03.764 [info] Starting processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server...
2025-06-18 14:42:03.859 [info] #getSession: Failed to running method. Error: 'Canceled: Canceled'
2025-06-18 14:42:05.477 [info] Using existing .NET runtime at "C:\Program Files\dotnet\dotnet.exe" to load Dev Kit processes.
2025-06-18 14:42:05.626 [info] .NET Sdk found: "C:\Program Files\dotnet\dotnet.exe".
2025-06-18 14:42:10.765 [info] .NET server started and IPC established in 5135ms
2025-06-18 14:42:10.791 [info] Completed Spawn .NET server (7039ms)
2025-06-18 14:42:23.417 [info] Completed processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server (19653ms)
2025-06-18 14:42:23.431 [info] Starting restoring NuGet packages...
2025-06-18 14:42:23.432 [info] Selected configuration: <Default>, active configuration: Debug|x64
2025-06-18 14:42:23.432 [info] Completed opening a solution (19667ms)
2025-06-18 14:42:23.450 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 14:43:03.991 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (40556ms)
2025-06-18 14:43:03.992 [info] Completed restoring NuGet packages (40561ms)
2025-06-18 14:52:04.704 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 14:52:34.573 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (29875ms)
2025-06-18 14:52:46.595 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 14:53:36.308 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (49722ms)
2025-06-18 14:53:52.074 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 14:54:25.908 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (33902ms)
2025-06-18 14:54:26.520 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 14:54:43.409 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (16894ms)
2025-06-18 14:55:43.282 [info] C# Dev Kit deactivate() is now executing...
2025-06-18 14:55:48.902 [info] Starting Spawn .NET server...
2025-06-18 14:55:48.902 [info] Using dotnet resolution provided by ".NET Install Tool".
2025-06-18 14:55:48.909 [info] Starting opening a solution...
2025-06-18 14:55:48.910 [info] Starting processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server...
2025-06-18 14:55:51.108 [info] Using existing .NET runtime at "C:\Program Files\dotnet\dotnet.exe" to load Dev Kit processes.
2025-06-18 14:55:51.471 [info] .NET Sdk found: "C:\Program Files\dotnet\dotnet.exe".
2025-06-18 14:55:55.173 [info] .NET server started and IPC established in 3699ms
2025-06-18 14:55:55.188 [info] Completed Spawn .NET server (6290ms)
2025-06-18 14:56:07.353 [info] Completed processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server (18443ms)
2025-06-18 14:56:07.366 [info] Starting restoring NuGet packages...
2025-06-18 14:56:07.367 [info] Selected configuration: <Default>, active configuration: Debug|x64
2025-06-18 14:56:07.367 [info] Completed opening a solution (18457ms)
2025-06-18 14:56:07.381 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 14:56:11.608 [info] Starting Query for all projects...
2025-06-18 14:56:35.507 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (28137ms)
2025-06-18 14:56:35.507 [info] Completed restoring NuGet packages (28141ms)
2025-06-18 14:56:55.396 [info] Completed Query for all projects (43788ms)
2025-06-18 15:31:07.564 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:31:53.064 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (45511ms)
2025-06-18 15:37:22.176 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:38:03.419 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (41266ms)
2025-06-18 15:38:03.443 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:38:50.602 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (47166ms)
2025-06-18 15:38:56.669 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:39:09.096 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (12432ms)
2025-06-18 15:44:32.465 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:44:43.132 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (10675ms)
2025-06-18 15:45:05.035 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:45:18.267 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (13241ms)
2025-06-18 15:53:02.102 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:53:12.327 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (10231ms)
2025-06-18 15:54:39.153 [info] C# Dev Kit deactivate() is now executing...
2025-06-18 15:54:44.727 [info] Starting Spawn .NET server...
2025-06-18 15:54:44.728 [info] Using dotnet resolution provided by ".NET Install Tool".
2025-06-18 15:54:44.766 [info] Starting opening a solution...
2025-06-18 15:54:44.766 [info] Starting processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server...
2025-06-18 15:54:45.020 [info] #getSession: Failed to running method. Error: 'Canceled: Canceled'
2025-06-18 15:54:47.176 [info] Using existing .NET runtime at "C:\Program Files\dotnet\dotnet.exe" to load Dev Kit processes.
2025-06-18 15:54:47.488 [info] .NET Sdk found: "C:\Program Files\dotnet\dotnet.exe".
2025-06-18 15:54:50.801 [info] .NET server started and IPC established in 3310ms
2025-06-18 15:54:50.819 [info] Completed Spawn .NET server (6094ms)
2025-06-18 15:54:55.031 [info] Completed processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server (10265ms)
2025-06-18 15:54:55.046 [info] Starting restoring NuGet packages...
2025-06-18 15:54:55.047 [info] Selected configuration: <Default>, active configuration: Debug|x64
2025-06-18 15:54:55.047 [info] Completed opening a solution (10281ms)
2025-06-18 15:54:55.070 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 15:55:04.889 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (9833ms)
2025-06-18 15:55:04.889 [info] Completed restoring NuGet packages (9843ms)
2025-06-18 16:08:10.440 [info] C# Dev Kit deactivate() is now executing...
2025-06-18 16:08:15.153 [info] Starting Spawn .NET server...
2025-06-18 16:08:15.153 [info] Using dotnet resolution provided by ".NET Install Tool".
2025-06-18 16:08:15.155 [info] Starting opening a solution...
2025-06-18 16:08:15.155 [info] Starting processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server...
2025-06-18 16:08:15.356 [info] #getSession: Failed to running method. Error: 'Canceled: Canceled'
2025-06-18 16:08:17.168 [info] Using existing .NET runtime at "C:\Program Files\dotnet\dotnet.exe" to load Dev Kit processes.
2025-06-18 16:08:17.653 [info] .NET Sdk found: "C:\Program Files\dotnet\dotnet.exe".
2025-06-18 16:08:25.907 [info] .NET server started and IPC established in 8252ms
2025-06-18 16:08:25.921 [info] Completed Spawn .NET server (10771ms)
2025-06-18 16:08:35.820 [info] Completed processing the solution file "C:\sources\coes\COES\COES.sln" in Dev Kit server (20665ms)
2025-06-18 16:08:35.902 [info] Starting restoring NuGet packages...
2025-06-18 16:08:35.902 [info] Selected configuration: <Default>, active configuration: Debug|x64
2025-06-18 16:08:35.902 [info] Completed opening a solution (20747ms)
2025-06-18 16:08:35.921 [info] Starting command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive...
2025-06-18 16:09:13.382 [info] Completed command: "C:\Program Files\dotnet\dotnet.exe" restore C:\sources\coes\COES\COES.sln --interactive (37476ms)
2025-06-18 16:09:13.383 [info] Completed restoring NuGet packages (37480ms)

Steps to reproduce

This is a net48 project with mostly unit tests. The templates folder is just data for the unit tests, so we have:

  <ItemGroup>
    <Compile Remove="Features\Templates\**" />
  </ItemGroup>

However, even with this, it gives errors.

Expected behavior

No errors

Actual behavior

Image

Additional context

BenjaminBrienen avatar Jun 18 '25 14:06 BenjaminBrienen

@BenjaminBrienen , we're sorry you are running into this. The bulk of the Razor functionality ships in the C# Extension; when you indicate in the title that the Razor Extension is not installed, which extension do you mean?

phil-allen-msft avatar Jun 19 '25 22:06 phil-allen-msft

I mentioned it because if you search for issues in the past, this exact error was actually coming from another extension that I haven't heard of, which was referred to as "the Razor extension".

I am getting this error, but I felt like it was worth mentioning that this is not the same issue.

BenjaminBrienen avatar Jun 19 '25 22:06 BenjaminBrienen

I can't repro this trying various things to exclude files from the project etc. but it could be that this was fixed in subsequent updates. @BenjaminBrienen does this problem still repro for you? And if so, could you include the version info for the C# extension you're running? The details and logs in this issue are for the Dev Kit extension, but there really isn't anything much specific to Razor in that extension, all of our stuff lives in the C# extension. There is a "Report a Razor issue" command you could run that will put a bunch of info on the clipboard that you could paste in here, if thats easier.

Also, if you're trying to completely ignore a folder from a project, you'll probably get better results if you do this instead of the <Compile Remove:

<PropertyGroup>
    <DefaultItemExcludes>$(DefaultItemExcludes);Features\Templates\**</DefaultItemExcludes>
</PropertyGroup>

That will ensure that all files in the templates folder are excluded, not just compile items. Since .razor and .cshtml files are not compile items, it might make things a bit more predictable. Note that using DefaultItemExcludes will also hide the items from solution explorer, but you can restore them there with <None Include="Features\Templates\**" /> if you want.

davidwengier avatar Jul 17 '25 23:07 davidwengier

I'm trying to make it as clear as possible that I am not using the Razor extension, only C# Dev Kit. Yes, it reproduces reliably. I'll try to get a sample project for you.

BenjaminBrienen avatar Jul 17 '25 23:07 BenjaminBrienen

Not only is it clear that you're not using the Razor extension, there also is no such thing (or at least, no official one). There is however a "C#" and a "C#Dev Kit" extension. You can't use the latter without the former, but they are separate so have their own versions. Almost all of the Razor functionality in VS Code is part of the "C#" extension.

eg, your extensions pane in VS Code should look something like this:

Image

Regardless though, I'd very much appreciate a sample project, so thank you very much :)

davidwengier avatar Jul 17 '25 23:07 davidwengier