dotnet / vscode-csharp

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

Omnisharp doesn't find System on Dotnet SDK >= 3.0 #3917

Open ishc3ice opened 4 years ago

ishc3ice commented 4 years ago

Issue Description

When I open a Project with OmniSharp and the target Framework is set to 2.1, it works perfectly, but if i go higher than that (>= 3.0), it just says "The type or namespace name 'System' could not be found". It works perfectly when I press F5, or do dotnet run

Steps to Reproduce

Create any .NET Core >= 3.0 project and try to use Omnisharp

Expected Behavior

It should work on any .NET Core version

Actual Behavior

It doesn't and can't find any .NET Core classes

Logs

OmniSharp log

Post the output from Output-->Starting OmniSharp server at 7/19/2020, 8:38:47 PM Target: /home/noah/soda-lake-s-share/code/c#/hi ``` OmniSharp server started with Mono 6.10.0. Path: /home/noah/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/OmniSharp.exe PID: 119169 [info]: OmniSharp.Stdio.Host Starting OmniSharp on arch 0.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Located 2 MSBuild instance(s) 1: Mono 16.4 - "/usr/lib/mono/msbuild/Current/bin" 2: StandAlone 16.4 - "/home/noah/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin" [info]: OmniSharp.MSBuild.Discovery.MSBuildLocator Registered MSBuild instance: Mono 16.4 - "/usr/lib/mono/msbuild/Current/bin" CscToolExe = csc.exe CscToolPath = /home/noah/.vscode/extensions/ms-dotnettools.csharp-1.22.1/.omnisharp/1.35.3/omnisharp/.msbuild/Current/Bin/Roslyn [info]: OmniSharp.Cake.CakeProjectSystem Detecting Cake files in '/home/noah/soda-lake-s-share/code/c#/hi'. [info]: OmniSharp.Cake.CakeProjectSystem Could not find any Cake files [info]: OmniSharp.MSBuild.ProjectSystem No solution files found in '/home/noah/soda-lake-s-share/code/c#/hi' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.Script.ScriptProjectSystem Detecting CSX files in '/home/noah/soda-lake-s-share/code/c#/hi'. [info]: OmniSharp.Script.ScriptProjectSystem Could not find any CSX files [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.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.MSBuild.ProjectManager Loading project: /home/noah/soda-lake-s-share/code/c#/hi/hi.csproj [info]: OmniSharp.WorkspaceInitializer Configuration finished. [info]: OmniSharp.Stdio.Host Omnisharp server running using Stdio at location '/home/noah/soda-lake-s-share/code/c#/hi' on host 119063. [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Adding project '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Update project: hi [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /home/noah/soda-lake-s-share/code/c#/hi/hi.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Update project: hi [warn]: OmniSharp.MSBuild.PackageDependencyChecker hi: Did not find 'Microsoft.NETCore.App' in lock file. [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /home/noah/soda-lake-s-share/code/c#/hi/hi.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Update project: hi [info]: OmniSharp.MSBuild.ProjectManager Queue project update for '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj' [info]: OmniSharp.MSBuild.ProjectManager Loading project: /home/noah/soda-lake-s-share/code/c#/hi/hi.csproj [info]: OmniSharp.MSBuild.ProjectManager Successfully loaded project file '/home/noah/soda-lake-s-share/code/c#/hi/hi.csproj'. [info]: OmniSharp.MSBuild.ProjectManager Update project: hi [info]: OmniSharp.Roslyn.CSharp.Services.Diagnostics.ReAnalyzeService Queue analysis for all projects.


### C# log ###
<details>Post the output from Output-->-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.3/System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/home/noah/soda-lake-s-share/code/c#/hi/bin/Debug/netcoreapp3.1/hi.dll'. Symbols loaded.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.3/System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.3/System.Console.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.3/System.Threading.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.3/System.Runtime.Extensions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
</details>

## Environment information ##

**VSCode version**: 1.47.2
**C# Extension**: 1.22.1

<details><summary>Mono Information</summary>
        OmniSharp using global mono :6.10.0</details>
<details><summary>Dotnet Information</summary>
.NET Core SDK (reflecting any global.json):
 Version:   3.1.103
 Commit:    6f74c4a1dd

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /usr/share/dotnet/sdk/3.1.103/

Host (useful for support):
  Version: 3.1.3
  Commit:  ed88943d24

.NET Core SDKs installed:
  2.1.808 [/usr/share/dotnet/sdk]
  3.1.103 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.NETCore.App 2.1.20 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
</details>
<details><summary>Visual Studio Code Extensions</summary>

|Extension|Author|Version|
|---|---|---|
|csharp|ms-dotnettools|1.22.1|;

</details>
filipw commented 4 years ago

looks like you have an outdated installation of global Mono. please update to at least 6.4 (ideally 6.10)

ishc3ice commented 4 years ago

looks like you have an outdated installation of global Mono. please update to at least 6.4 (ideally 6.10)

I already have Mono 6.10

OmniSharp using global mono :6.10.0

filipw commented 4 years ago

yes but it must be missing the necessary msbuild (16.3+)

ishc3ice commented 4 years ago

~ $ pacman -Q | grep msbuild mono-msbuild 16.6.xamarinxplat.2020.04.29.14.43-1

filipw commented 4 years ago

I am not very familiar with Arch but we have only partial support for ot though see https://github.com/OmniSharp/omnisharp-roslyn#introduction

what your log shows is that the global mono you have doesn't have correct new msbuild bundled, hence the problem

what you need is the equivalent of mono-devel for Ubuntu

JoeRobich commented 4 years ago

I believe that Arch has a msbuild-stable package that is known to work. See this comment https://github.com/OmniSharp/omnisharp-vscode/issues/3769#issuecomment-630291840

filipw commented 4 years ago

ah thanks @JoeRobich I couldn't find that. I updated the instructions here https://github.com/OmniSharp/omnisharp-roslyn/pull/1859

ishc3ice commented 4 years ago

I replaced mono-msbuild with msbuild-stable, and it hasn't changed anything

fosspill commented 4 years ago

I can confirm that I'm experiencing this too. msbuild-stable sadly doesn't seem to resolve anything.

This issue also persists on the flatpak version, which can make sense since it seems to be referencing local packages as well.

Pressing F5 seems to be a decent workaround for now as it seems to help highlight actual issues in the code :)

robertwahler commented 3 years ago

I have this issue on macOS. Using stable mono 6.10, tried 6.12 too, but no go. I can only get OmniSharp 1.23.4 to provide partial IntelliSense for dotnet core projects. It can't handle any references to System.Threading.* using the global mono but it does work if I change to "omnisharp.useGlobalMono": "never".

I'd leave it at that but I can't use the never setting as it is only allowed in user and not workspace. I also use Unity and that requires real mono, the internal Omnisharp version will not function.

Basically, in order to keep working, I can only have one project open at a time and I have to swap the omnisharp.useGlobalMono setting to and from always and never before changing projects. I wish I understood the real issue so I could address it.

filipw commented 3 years ago

the problem is the incompatibility between the lowest MSBuild version required by the new .NET Core SDKs (16.7+) and the version available in any publicly available Mono (16.6)

the bundled Mono of Omnisharp is something we build ourselves so it has 16.8 and hence it works with latest.NET Core including .NET 5.0

you can find more info here https://github.com/OmniSharp/omnisharp-vscode/issues/4007#issuecomment-677405332 and here https://github.com/mono/mono/issues/20250

robertwahler commented 3 years ago

Thanks so much @filipw! I was able to configure an environment that works for Unity and DotNet Core at the same time with your information.

Here is what I had to do to work in VSCode in both Unity and DotNet core without changing the Omnisharp.useGlobalMono setting several times a day. The following setup also allows me to have Unity and DotNet Core projects open at the same time.