vscode-csharp: The type or namespace name 'System' could not be found
Environment data
dotnet --info
output:
.NET Command Line Tools (2.1.103)
Product Information:
Version: 2.1.103
Commit SHA-1 hash: 60218cecb5
Runtime Environment:
OS Name: Windows OS
Version: 6.1.7601 OS
Platform: Windows
RID: win7-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.103\
Microsoft .NET Core Shared Framework Host
Version : 2.0.6
Build : 74b1c703813c8910df5b96f304b0f2b78cdf194d
VS Code version:
1.21.1
C# Extension version:
1.14.0
Issue:
I upgraded from VS Code 1.19 and C# Extension 1.13 to the latest VS Code and # Extension and all of sudden every reference is all messed up, but I’m able to do dotnet build
without issues. Attached screenshot and trace logs from OmniSharp.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 53 (13 by maintainers)
Commits related to this issue
- Log evaluated projects at the debug log level This should help diagnose missing references in https://github.com/OmniSharp/omnisharp-vscode/issues/2147 — committed to rchande/omnisharp-roslyn by deleted user 6 years ago
@dmumladze Thanks for including your omnisharp log. Can you try deleting the
C:\Users\{username}\.vscode\extensions\ms-vscode.csharp-1.14.0\.omnisharp
directory and see if that helps? Also, it looks like you’re on a pretty recent release of the CLI. Have you updated the CLI recently, and if so, was everything working before you updated?Disable the C# plugin and the error messages will go away (KISS).
@dmumladze My current hypothesis is that something is going wrong when OmniSharp uses MSBuild to build your project that results in us not finding the right reference paths. I added some diagnostics to OmniSharp to collect more info. Please give this a try: Install the 15.0-beta4 release of C# extension for VS Code: https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.15.0-beta4 (basically, download the .vsix file and use the extension manager in VS Code to “install from VSIX”) In “user settings”, set 2 options:
"omnisharp.loggingLevel": "debug"
: I think you already had this set, causes O# to log more info"omnisharp.path": "latest"
: We added a new feature to the extension that will download the latest build of Omnisharp from https://github.com/OmniSharp/omnisharp-roslyn. In this case, I recently added https://github.com/OmniSharp/omnisharp-roslyn/pull/1151, which will log more project infoThen, do whatever you did to load your project and share your OmniSharp log again. Note that it will print lots of file paths. If you want to elide your username, go ahead, but try to leave paths as intact as possible. Hopefully this will help us diagnose what’s happening on your machine.
OmniSharp uses msbuild from Visual Studio 2019 if it’s installed on your machine. The minimum version of msbuild needed for .NET Core 3.0 is 16.3, which only ships with VS 2019 16.3.x.
So if you had VS 2019 16.2, then OmniSharp used that msbuild and it was too old to support .NET Core 3.0 RTM which caused your errors.
We’ve merged a fix to #2295 to OmniSharp. Try setting
"omnisharp.path"
in the VS Code settings to"latest"
. This will cause C# for VS Code to download and use the latest build of OmniSharp, which contains that fix.if it’s not installed, then it uses it’s own bundled msbuild which is now version 16.3 (but a simpler version that cannot handle i.e some Unity projects or complex legacy frameworks, that’s why VS is always preferred).
.NET Core 3.0 has raised the minimum msbuild level required from 16.0 to 16.3 between the final previews and RTM version, which caught us a bit off guard, that’s why OmniSharp worked fine with previews but not RTM of .NET Core 3.0, as we used to ship with 16.0 - which is really what this entire issue has been about.
hope this explains
Confirmed that this remains an issue even with a fresh project created with
dotnet new console
. The resulting csproj:Experiencing the same issue on macOS.
Attempted resolution:
Attempted with .NET Core 3.0 Preview 1:
Attempted again with .NET Core 3.0 Preview 3:
C# extension constantly tells me I need to restore packages. Upon restoring, it immediately prompts again. However, my project doesn’t rely on any NuGet packages:
Here’s what shows up when I click the
Restore
button:There are two warnings in the OmniSharp log:
Presumably 3.0.0-preview-27324-5 < 3.0.0. Since I’m not explicitly specifying a version anywhere besides TargetFramework, and that TargetFramework works fine in VS 2019 Preview, I’m unsure how to proceed.
Issue vanishes if I target netcoreapp2.2.
Installing VS 2019 16.3.x worked for me 👍
@dmumladze Does the error still reproduce for the latest version of the C# extension ?
not sure if this is related/helpful. I had two visual studio code instances open, one was my angular CLI project (which was open first) then I launched a new visual studio code instance and opened my C# project folder and received this error/issue.
after closing both and only opening my C# project the issue went away.
To reinstall omnisharp, you also need to delete the
install.LOCK
file in the extension folder as mentioned above.