Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predefined type 'System.Object' is not defined or imported .net 4.6

I'm using MVC 5 and .net 4.6 to create a web API that my mobile app can connect too.

Whenever I build the project I get hundreds of errors telling me that I need to add references that are already there and that literally every type in my project 'does not exist'. Some examples of these errors: (Not including the one in the title)

ErrorList

What I've tried:

  • Added a reference to System.Runtime via nuGet. (A recommendation from this question.)
  • Removed aspnetcore50 from the frameworks in the project.json file. (Another recommendation, this question.)
  • Restarting VS2015, my machine.
  • Going through the nuGet package manager and upgrading every package in my project to the latest.
  • Actually making sure I can see the references in the references node of the solution explorer.

UPDATE: -My project.json file looks like this. (After modifying based on Karls answer. The error list is now down to ten, however they are still the same errors as before.)

{
  "commands": {
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
  },
  "dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
    "Microsoft.AspNet.Mvc": "6.0.0-beta5",
    "System.Runtime": "4.0.20-beta-23019"
  },
  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "frameworks": {
    "dnx451": {
      "frameworkAssemblies": {
        "System.Data": "4.0.0.0",
        "System.Data.DataSetExtensions": "4.0.0.0",
        "System.Data.Linq": "4.0.0.0"
      }
    }
  },
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "version": "1.0.0-*",
  "webroot": "wwwroot"
}
like image 370
KidCode Avatar asked Jul 04 '15 19:07

KidCode


4 Answers

Remove bin and obj and rebuild.

like image 124
gneric Avatar answered Oct 25 '22 11:10

gneric


This wasted lot of my time. Close the visual studio. Delete the .vs folder and restart visual studio. Everything should work fine.

Usually this happens when you change branches or merge branches.

like image 39
Tharindu Jayasinghe Avatar answered Oct 25 '22 12:10

Tharindu Jayasinghe


I ran dotnet restore command on the Package manager console and the problem was solved.

like image 54
Navid_pdp11 Avatar answered Oct 25 '22 12:10

Navid_pdp11


I had the same problem. I spent two days trying to resolve this problem. I tried reinstalling Visual Studio, cleared Visual Studio cache, uninstalled Visual Studio or setup Windows 10 again => but with no success.

You can try follow steps which worked for me:

  1. Close Visual Studio
  2. Delete the packages folder in Solution folder
  3. Open Visual Studio and rebuild solution

Good luck

like image 14
Bình Nguyễn Quang Avatar answered Oct 25 '22 11:10

Bình Nguyễn Quang