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.

OmniSharp.log

capture

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 53 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@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 info

Then, 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:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

</Project>

Experiencing the same issue on macOS.

Attempted resolution:

  1. Uninstall C# extension within VS Code
  2. Reload VS Code
  3. Exit VS Code
  4. rm -rf ~/.vscode/extensions/ms-vscode.csharp-1.17.1/
  5. Launch VS Code
  6. Install C# extension
  7. Restart VS Code
  8. Wait for OmniSharp to download

Attempted with .NET Core 3.0 Preview 1:

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview-010184
 Commit:    c57bde4593

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.0.100-preview-010184/

Host (useful for support):
  Version: 3.0.0-preview-27324-5
  Commit:  63a01b08e5

.NET Core SDKs installed:
  2.1.302 [/usr/local/share/dotnet/sdk]
  3.0.100-preview-010184 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview-27324-5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Attempted again with .NET Core 3.0 Preview 3:

NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview3-010431
 Commit:    d72abce213

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.0.100-preview3-010431/

Host (useful for support):
  Version: 3.0.0-preview3-27503-5
  Commit:  3844df9537

.NET Core SDKs installed:
  2.1.302 [/usr/local/share/dotnet/sdk]
  3.0.100-preview-010184 [/usr/local/share/dotnet/sdk]
  3.0.100-preview3-010431 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview3-19153-02 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview-27324-5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview3-27503-5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

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:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
    <NullableReferenceTypes>true</NullableReferenceTypes>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
  </PropertyGroup>

</Project>

Here’s what shows up when I click the Restore button:

  Persisting no-op dg to /Users/paul/git/Test/Test.Base/obj/Test.Base.csproj.nuget.dgspec.json
  Restore completed in 11.5 sec for /Users/paul/git/TEst/Test.Base/Test.Base.csproj.
Done: 0.

There are two warnings in the OmniSharp log:

[warn]: OmniSharp.MSBuild.PackageDependencyChecker
        Test.Base: Found implicit package reference 'Microsoft.NETCore.App', but none of the versions in the lock file ("3.0.0-preview-27324-5") satisfy [3.0.0, )
[warn]: OmniSharp.MSBuild.PackageDependencyChecker
        Test.Base: Did not find 'Microsoft.NETCore.App' in lock file.

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.

% dotnet list Test.Base/Test.Base.csproj package
Project 'Test.Base' has the following package references
   [netcoreapp3.0]:
   Top-level Package                      Requested                     Resolved
   > Microsoft.AspNetCore.App.Ref   (A)   [3.0.0-preview3-19153-02, )   3.0.0-preview3-19153-02
   > Microsoft.NETCore.App.Ref      (A)   [3.0.0-preview3-27503-5, )    3.0.0-preview3-27503-5
   > Microsoft.NETCore.Platforms    (A)   [3.0.0-preview3.19128.7, )    3.0.0-preview3.19128.7
   > Microsoft.WindowsDesktop.App   (A)   [3.0.0-preview3-27504-2, )    3.0.0-preview3-27504-2

(A) : Auto-referenced package.

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.