Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Predefined type 'System.Object' is not defined or imported

In .NET core project, I changed the all projects name than after reloading all project that time many errors were showing approx 3225. And mainly all errors are related to system namespace like

  • System.Object not defined or imported
  • System.Boolean not defined or imported
  • Task does not exist
  • namespace ArgumentNullException could not be found

How do I resolve all those errors?

like image 927
Akash Limbani Avatar asked Oct 19 '18 04:10

Akash Limbani


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.


2 Answers

  • close VS
  • delete the bin, obj and .vs (may be hidden) folders
  • manually run dotnet restore
  • reopen the project in VS

That fixes most things.

like image 72
Marc Gravell Avatar answered Oct 06 '22 11:10

Marc Gravell


I was hitting this in VS Code. In Windows Terminal, dotnet build and dotnet run ran fine, but I was getting the errors in VS Code. The delete/restore/reopen answer did not fix it.

It seems it was an issue where I had an outdated version of Visual Studio confusing the C#/OmniSharp extension in VS Code.

The OmniSharp log included something like this:

[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Visual Studio Enterprise 2019 16.8.30907.101 16.8.3 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"
            2: StandAlone 17.0.0 - "c:\Users\foo\.vscode-insiders\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Enterprise 2019 16.8.30907.101 16.8.3 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"

That version of Visual Studio 2019 did not have the .NET 6.0 SDK installed, and I couldn't find it in the VS Installer.

So I installed Visual Studio 2022 and the .NET 6.0 SDK as part of that install. Now my log looks like this:

[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 3 MSBuild instance(s)
            1: Visual Studio Enterprise 2022 17.0.31912.275 17.0.0 - "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin"
            2: Visual Studio Enterprise 2019 16.8.30907.101 16.8.3 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"
            3: StandAlone 17.0.0 - "c:\Users\foo\.vscode-insiders\extensions\ms-dotnettools.csharp-1.23.16\.omnisharp\1.37.16\.msbuild\Current\Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Visual Studio Enterprise 2022 17.0.31912.275 17.0.0 - "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin"

And the errors are gone!

like image 33
citelao Avatar answered Oct 06 '22 10:10

citelao