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

Type or Namespace name not found

Open XelaMon opened this issue 1 year ago • 3 comments

Type: Bug

Issue Description

I'm seeing a type or namespace name not found error in the C# extension on Visual Studio code for a specific namespace in my project. This works fine on full Visual Studio and dotnet build executes without errors.

Also seeing a bunch of these but unclear if they are related:

StreamJsonRpc.LocalRpcException: Resolve version '2025-05-12T23:38:46.1115231Z-10095-0' does not match current version '2025-05-12T23:38:47.3375546Z-10288-0' at Microsoft.CodeAnalysis.LanguageServer.Handler.CodeLens.CodeLensResolveHandler.HandleRequestAsync(CodeLens request, RequestContext context, CancellationToken cancellationToken) in /_/src/LanguageServer/Protocol/Handler/CodeLens/CodeLensResolveHandler.cs:line 56 at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`1.StartRequestAsync[TRequest,TResponse](TRequest request, TRequestContext context, IMethodHandler handler, String language, CancellationToken cancellationToken) in /_/src/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 191

Steps to Reproduce

The code here is Microsoft-internal. If you reach out to me on Teams (almarcel), I'd be happy to show you!

Expected Behavior

A 'type or namespace name not found error' alongside a handful of 'name does not exist in the current context' errors.

Actual Behavior

I'm not expecting to see these errors!

Logs

C# log

Code is Microsoft-internal so I'm hesitant to put logs in here that have info about it but happy to show you if you reach out!

C# LSP Trace Logs

Code is Microsoft-internal but happy to show you if you reach out!

Environment information

VSCode version: 1.101.0-insider C# Extension: 2.72.34 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 9.0.203 Commit: dc7acfa194 Workload version: 9.0.200-manifests.12d79ccf MSBuild version: 17.13.20+a4ef1e90f

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

.NET workloads installed: [aspire] Installation Source: VS 17.13.35931.197 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

Configured to use loose manifests when installing new manifests.

Host: Version: 9.0.4 Architecture: x64 Commit: f57e6dc747

.NET SDKs installed: 8.0.408 [C:\Program Files\dotnet\sdk] 9.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [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.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [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.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [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.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.4 [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

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

Visual Studio Code Extensions
Extension Author Version Folder Name
azure-dev ms-azuretools 0.9.0 ms-azuretools.azure-dev-0.9.0
azure-pipelines ms-azure-devops 1.249.0 ms-azure-devops.azure-pipelines-1.249.0
azure-repos ms-vscode 0.41.2024112101 ms-vscode.azure-repos-0.41.2024112101
copilot GitHub 1.318.1558 github.copilot-1.318.1558
copilot-chat GitHub 0.28.2025051202 github.copilot-chat-0.28.2025051202
csdevkit ms-dotnettools 1.18.25 ms-dotnettools.csdevkit-1.18.25-win32-x64
csharp ms-dotnettools 2.72.34 ms-dotnettools.csharp-2.72.34-win32-x64
debugpy ms-python 2025.8.0 ms-python.debugpy-2025.8.0-win32-x64
markdown-mermaid bierner 1.28.0 bierner.markdown-mermaid-1.28.0
microsoft-testing ms-azure-load-testing 0.1.13 ms-azure-load-testing.microsoft-testing-0.1.13
python ms-python 2025.6.0 ms-python.python-2025.6.0-win32-x64
remote-containers ms-vscode-remote 0.414.0 ms-vscode-remote.remote-containers-0.414.0
remote-repositories ms-vscode 0.43.2024112101 ms-vscode.remote-repositories-0.43.2024112101
remotehub GitHub 0.65.2024112101 github.remotehub-0.65.2024112101
vscode-ai-foundry TeamsDevApp 0.4.0 teamsdevapp.vscode-ai-foundry-0.4.0
vscode-azure-github-copilot ms-azuretools 0.3.268 ms-azuretools.vscode-azure-github-copilot-0.3.268-win32-x64
vscode-azureappservice ms-azuretools 0.26.1 ms-azuretools.vscode-azureappservice-0.26.1
vscode-azurecontainerapps ms-azuretools 0.8.2 ms-azuretools.vscode-azurecontainerapps-0.8.2
vscode-azurefunctions ms-azuretools 1.17.2 ms-azuretools.vscode-azurefunctions-1.17.2
vscode-azureresourcegroups ms-azuretools 0.10.10 ms-azuretools.vscode-azureresourcegroups-0.10.10
vscode-azurestaticwebapps ms-azuretools 0.13.1 ms-azuretools.vscode-azurestaticwebapps-0.13.1
vscode-azurestorage ms-azuretools 0.16.4 ms-azuretools.vscode-azurestorage-0.16.4
vscode-azurevirtualmachines ms-azuretools 0.6.8 ms-azuretools.vscode-azurevirtualmachines-0.6.8
vscode-bicep ms-azuretools 0.35.1 ms-azuretools.vscode-bicep-0.35.1
vscode-containers ms-azuretools 2.0.1 ms-azuretools.vscode-containers-2.0.1
vscode-cosmosdb ms-azuretools 0.26.0 ms-azuretools.vscode-cosmosdb-0.26.0
vscode-dotnet-runtime ms-dotnettools 2.3.3 ms-dotnettools.vscode-dotnet-runtime-2.3.3
vscode-httpyac anweber 6.16.7 anweber.vscode-httpyac-6.16.7
vscode-node-azure-pack ms-vscode 1.5.0 ms-vscode.vscode-node-azure-pack-1.5.0
vscode-pylance ms-python 2025.4.1 ms-python.vscode-pylance-2025.4.1

Extension version: 2.72.34 VS Code version: Code - Insiders 1.101.0-insider (5d3e84d3aaaea9e132bad476f1be5a4846289b75, 2025-05-12T05:04:38.258Z) OS version: Windows_NT x64 10.0.26410 Modes:

System Info
Item Value
CPUs 13th Gen Intel(R) Core(TM) i7-13700K (24 x 3418)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 63.70GB (36.19GB free)
Process Argv G:\repos\GamePass.Catalog\ --crash-reporter-id 4b457881-4839-4511-9b13-9af091108d7e
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt551cf:31249598
vscod805cf:30301675
c4g48928:30535728
a9j8j154:30646983
962ge761:30841072
dsvsc014:30777825
dsvsc015:30821418
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:30980852
dwnewjupytercf:31046870
pythonrstrctxt:31093868
nativeloc1:31118317
e80f6927:31120813
dwcopilot:31158714
5b1c1929:31184661
471b6256:31240254
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
g012b348:31231168
pythoneinst12:31251391
bgtreat:31252123
c7cif404:31294349
31787653:31262186
3e8i5726:31271747
pythonpulldiag:31287486
6gi0g917:31259950
editoredits36407:31282444
996jf627:31264550
pythonrdcb7:31268811
usemplatestapi:31297334
i53e4855:31297587
747dc170:31275146
pythoncompactctx:31296835
6518g693:31302842
pylancecolor:31288664
generatesymbolt:31280541
convertfstringf:31280702
gendocf:31280703
pylancequickfixf:31296867
g7g4a411:31305772
46eeb794:31305831

XelaMon avatar May 12 '25 23:05 XelaMon

Got access to the internal repo and was able to create a more minimal repro: ConsoleAppPlatform.zip

Image

Debugging this on the Roslyn side, we get the following information from the project system about DependencyProject.csproj. On initial load, the output paths on the properties are as follows:

Kind Roslyn Property Value
TargetPath OutputFilePath C:\Users\dabarbet\source\repos\trash\ConsoleAppPlatform\Drop\Debug\x64\DependencyProject\net6.0\DependencyProject.dll
TargetRefPath OutputRefFilePath C:\Users\dabarbet\source\repos\trash\ConsoleAppPlatform\Intermediate\DependencyProject\Debug\x64\net6.0\ref\DependencyProject.dll
IntermediateAssembly CompilationOutputAssemblyFilePath C:\Users\dabarbet\source\repos\trash\ConsoleAppPlatform\Intermediate\DependencyProject\Debug\x64\net6.0\DependencyProject.dll

Note the platform being x64 in this output path.

Then, DevKit tells us that ConsoleAppPlatform has a metadata reference to DependencyProject, and tells us the path is C:\Users\dabarbet\source\repos\trash\ConsoleAppPlatform\Intermediate\DependencyProject\Debug\AnyCPU\net6.0\ref\DependencyProject.dll

Note the platform being AnyCPU in the path.

Because the output paths for the DependencyProject.csproj do not match the added reference, we fail to resolve the project reference.

The Directory.Build.Props is likely important here. It contains the following:

<Platforms>x64</Platforms>

<Configuration Condition="'$(Configuration)'==''">Release</Configuration>
<Platform Condition="'$(Platform)'==''">Any CPU</Platform>

<CorrectedPlatform>$(Platform)</CorrectedPlatform>
<CorrectedPlatform Condition="'$(Platform)' == 'Any CPU'">AnyCPU</CorrectedPlatform>
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)Intermediate\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\$(CorrectedPlatform)\</IntermediateOutputPath>
<BaseOutputPath>$(MSBuildThisFileDirectory)Drop\</BaseOutputPath>
<OutputPath>$(BaseOutputPath)$(Configuration)\$(CorrectedPlatform)\$(MSBuildProjectName)\</OutputPath>
<OutDir Condition="'$(PlatformToolset)'!=''">$(OutputPath)</OutDir>

The DependencyProject therefore gets <Platforms>x64</Platforms>, but the output path is ...AnyCPU... based on the CorrectedPlatform.

I'm not quite sure if this is correct project authoring, but it does seem like DevKit should always be using AnyCPU as the output path, and not x64.

Additionally, adding <Platforms>x64;AnyCPU</Platforms> to DependencyProject.csproj resolves the issue

@lifengl would this be something to look at on CPS end, or the dotnet project system side?

dibarbet avatar May 22 '25 01:05 dibarbet

This issue has been transferred to https://github.com/microsoft/vscode-dotnettools/issues/2061

dibarbet avatar Jun 03 '25 00:06 dibarbet

Transferred to https://github.com/microsoft/vscode-dotnettools/issues/2061

dibarbet avatar Jun 03 '25 00:06 dibarbet