简体   繁体   中英

How can I resolve "The type or namespace name 'System' could not be found" errors in VS Code?

I'm using Visual Studio Code and .NET Core SDK 3.1.402, and trying to learn how to code C# (so I've got the most recent version of the extension downloaded.

When I create a new project (using cmd, dotnet new console), I am immediately greeted with several errors in the "Hello World" code that it generates automatically.

One of them right at the top is: Unnecessary using directive. [GradeBook]csharp(CS8019) The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [GradeBook]csharp(CS0246)

I'm also noticing problems in the obj\\debug{name}.AssemblyInfo.cs.

I've tried:

  1. Reinstalling Visual Studio Code
  2. Repairing .NET download
  3. Restarting Omnisharp

A basic replication here was that the first time I opened Visual Studio code after creating the project in the command prompt was that I was not greeted with errors. I saved and closed after a quick lesson, shut off and on my computer, reopened, and then the errors began showing.

I'm still able to run my code. But the red lines sure do make it hard to learn about the "real" issues.

How do I resolve something like this?

The only thing that worked for me was to completely uninstall my SDK, Visual Studio Code, and C# extension. Then reinstall them all. Once I did that, I was good to go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM