dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 672 forks source link

IntelliSense Does Not Work #4913

Open Fosol opened 2 years ago

Fosol commented 2 years ago

Issue Type: Bug

This issue has plagued me for years... Every new project I start with C# the editor messes up everything. It'll work for some files, not on others. To make matters worse tons of files will show up as red with errors. There are no errors... I can dotnet build and everything builds and works. Eventually through some magic and time it starts to work for my projects and I never know why. I have had these issues show up on every PC I've every used in the last 5 years.

I just started a new project with .NET 6... Again the same issue...

Currently I am using a Development Container for .NET 6. All I did was use the prebuilt containers and start a new project with dotnet new ....

VS Code version: Code 1.62.3 (ccbaa2d27e38e5afa3e5c21c1c7bef4657064247, 2021-11-17T08:11:14.551Z) OS version: Windows_NT x64 10.0.22000 Restricted Mode: No Remote OS version: Linux x64 5.10.16.3-microsoft-standard-WSL2

System Info |Item|Value| |---|---| |CPUs|11th Gen Intel(R) Core(TM) i7-1195G7 @ 2.90GHz (8 x 2918)| |GPU Status|2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled| |Load (avg)|undefined| |Memory (System)|15.72GB (3.72GB free)| |Process Argv|--folder-uri file:///c%3A/SourceCode/quartech/tno --crash-reporter-id aaaf5fb3-1b91-4b14-be8a-a303a6f44851| |Screen Reader|no| |VM|0%| |Item|Value| |---|---| |Remote|Dev Container: C# (.NET)| |OS|Linux x64 5.10.16.3-microsoft-standard-WSL2| |CPUs|11th Gen Intel(R) Core(TM) i7-1195G7 @ 2.90GHz (2 x 2918)| |Memory (System)|5.80GB (0.20GB free)| |VM|0%|
Extensions (18) Extension|Author (truncated)|Version ---|---|--- auto-close-tag|for|0.5.13 mysql-syntax|jak|1.3.1 workspace-cacheclean|Mam|0.0.2 dotenv|mik|1.0.1 vscode-azurevirtualmachines|ms-|0.4.1 remote-containers|ms-|0.205.2 remote-ssh|ms-|0.66.1 remote-ssh-edit|ms-|0.66.1 remote-wsl|ms-|0.58.5 vscode-remote-extensionpack|ms-|0.21.0 code-settings-sync|Sha|3.4.3 gitconfig|sid|2.0.1 vscode-icons|vsc|11.7.0 vscode-todo-highlight|way|1.0.5 dotnet-core-essentials|Kis|0.0.8 csharp|ms-|1.23.16 azurecli|ms-|0.5.0 sonar-dotnet-vscode|yag|1.0.0
A/B Experiments ``` vsliv368:30146709 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 pythontb:30283811 pythonvspyt551cf:30345471 pythonptprofiler:30281270 vshan820:30294714 vstes263:30335439 vscorecescf:30384386 pythondataviewer:30285071 vscod805cf:30301675 pythonvspyt200:30340761 binariesv615:30325510 bridge0708:30335490 dockerwalkthru:30377721 bridge0723:30353136 pythonrunftest32:30373476 pythonf5test824:30373475 javagetstartedt:30391933 pythonvspyt187:30373474 vsqsis200cf:30402084 vsaa593cf:30376535 vssld246cf:30401891 vscexrecpromptt1:30404947 vscop804cf:30404767 vs360:30404995 ```
Fosol commented 2 years ago

Perhaps related or unrelated. I'm testing on another computer atm. I see the following errors in the OmniSharp Log.

Microsoft.Build.Exceptions.InvalidProjectFileException: The project file could not be loaded. Could not find file

The solution builds fine of course. The file it's looking for doesn't exist. But I'm no sure why it's looking for the file. Essentially it appears to be expecting the project name to be identical to the folder it's in...

./Coevent.sln
./libs/entities/Coevent.Entities.csproj

It's expected to find a project libs\entities\entities.csproj. However in the the solution file it is correctly expressed.

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Coevent.Entities", "libs\entities\Coevent.Entities.csproj", "{10C60A6A-62D0-4652-B359-4FAD6498DF4B}"
EndProject
Fosol commented 2 years ago

Restarted VS Code and the The project file could not be loaded issue disappeared... Not exactly comforting that it takes restarting VS Code to fix certain bugs.

JoeRobich commented 2 years ago

@Fosol Can you share your complete OmniSharp Log from the Output pane?

It's expected to find a project libs\entities\entities.csproj.

What in the log is leading to this assumption?

Fosol commented 2 years ago

That particular issue disappeared on a restart of VS Code. However the initial issue of the container IntelliSense and errors showing up everywhere still remains.

Regarding that specific error message.

It's expected to find a project libs\entities\entities.csproj.

The issue appears to have been related to me renaming the project files. Even though I did everything correctly (it built without errors), OmniSharp couldn't handle it. I had to restart VS Code.

Fosol commented 2 years ago

I'm seeing warning like the following, even though I'm not using Visual Studio. I'm using VS Code.

C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(134,5): Error: Targeting .NET 6.0 in Visual Studio 2019 is not supported.
JoeRobich commented 2 years ago

The issue appears to have been related to me renaming the project files.

Ah, are the repro steps as follows?

  1. Open a folder containing a Solution file
  2. Rename one of the referenced project files
  3. Update Solution file with new project file name and save
  4. OmniSharp tries to update projects but is still looking for the project file that was renamed

I'm seeing warning like the following, even though I'm not using Visual Studio. I'm using VS Code.

@Fosol I imagine that the OmniSharp is using the MSBuild from your VS 2019 install. You can either install VS 2022 or enable the OmniSharp option to only use the included build tools (See https://github.com/OmniSharp/omnisharp-vscode/issues/4275#issuecomment-751718627).

Fosol commented 2 years ago

Those steps are correct.

Fosol commented 2 years ago

I have been working with a new computer today. Standing up the same project within a Development Container results in the IntelliSense not working again. It worked for about an hour, then stopped.

I suspect testing with Development Containers is limited.

JoeRobich commented 2 years ago

@Fosol If you can reproduce the failure, please share the OmniSharp Log from the VS Code output pane.

Fosol commented 2 years ago

Doesn't have much in it that I can tell.

Starting OmniSharp server at 11/30/2021, 9:22:04 PM
    Target: /workspaces/coevent/api/Coevent.sln

OmniSharp server started.
    Path: /home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/run
    PID: 727

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on debian 11.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
        Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 1 MSBuild instance(s)
            1: StandAlone 17.0.0 - "/home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        MSBUILD_EXE_PATH environment variable set to '/home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/MSBuild.exe'
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: StandAlone 17.0.0 - "/home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin"
            CscToolExe = csc.exe
            MSBuildToolsPath = /home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin
            CscToolPath = /home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild/Current/Bin/Roslyn
            BypassFrameworkInstallChecks = true
            MSBuildExtensionsPath = /home/vscode/.vscode-server/extensions/ms-dotnettools.csharp-1.23.16/.omnisharp/1.37.16/omnisharp/.msbuild
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/workspaces/coevent/api'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/workspaces/coevent/api/Coevent.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/workspaces/coevent/api/libs/entities/Coevent.Entities.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/workspaces/coevent/api/libs/dal/Coevent.Dal.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/workspaces/coevent/api/server/Coevent.Api.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/workspaces/coevent/api/test/Coevent.Test.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/workspaces/coevent/api/libs/core/Coevent.Core.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/workspaces/coevent/api'.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /workspaces/coevent/api/libs/entities/Coevent.Entities.csproj
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/workspaces/coevent/api' on host 473.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/workspaces/coevent/api/libs/entities/Coevent.Entities.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/workspaces/coevent/api/libs/entities/Coevent.Entities.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /workspaces/coevent/api/libs/dal/Coevent.Dal.csproj
Can't find custom attr constructor image: /workspaces/coevent/api/libs/entities/bin/Debug/net6.0/Coevent.Entities.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Can't find custom attr constructor image: /workspaces/coevent/api/libs/core/bin/Debug/net6.0/Coevent.Core.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/workspaces/coevent/api/libs/dal/Coevent.Dal.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/workspaces/coevent/api/libs/dal/Coevent.Dal.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /workspaces/coevent/api/server/Coevent.Api.csproj
Can't find custom attr constructor image: /workspaces/coevent/api/libs/dal/bin/Debug/net6.0/Coevent.Dal.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Can't find custom attr constructor image: /workspaces/coevent/api/libs/core/bin/Debug/net6.0/Coevent.Core.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Can't find custom attr constructor image: /workspaces/coevent/api/libs/entities/bin/Debug/net6.0/Coevent.Entities.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/workspaces/coevent/api/server/Coevent.Api.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/workspaces/coevent/api/server/Coevent.Api.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /workspaces/coevent/api/test/Coevent.Test.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/workspaces/coevent/api/test/Coevent.Test.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/workspaces/coevent/api/test/Coevent.Test.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /workspaces/coevent/api/libs/core/Coevent.Core.csproj
[info]: OmniSharp.MSBuild.ProjectManager
        Successfully loaded project file '/workspaces/coevent/api/libs/core/Coevent.Core.csproj'.
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/workspaces/coevent/api/libs/core/Coevent.Core.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Coevent.Entities
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Coevent.Dal
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Coevent.Api
Can't find custom attr constructor image: /workspaces/coevent/api/libs/dal/bin/Debug/net6.0/Coevent.Dal.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Can't find custom attr constructor image: /workspaces/coevent/api/libs/core/bin/Debug/net6.0/Coevent.Core.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
Can't find custom attr constructor image: /workspaces/coevent/api/libs/entities/bin/Debug/net6.0/Coevent.Entities.dll mtoken: 0x0a000001 due to: Cannot resolve dependency to assembly because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Coevent.Test
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: Coevent.Core
[info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.CSharpDiagnosticWorkerWithAnalyzers
        Solution initialized -> queue all documents for code analysis. Initial document count: 113.
Received response for /quickinfo but could not find request.
Fosol commented 2 years ago

IntelliSense is working on the same computer if I don't use a Development Container.

Standard template provided 6.0-bullseye-slim