Predefined type 'System.Object' is not def

2020-06-06 07:42发布

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"
}

10条回答
狗以群分
2楼-- · 2020-06-06 08:20

In my case, below are the steps I followed;

  1. I removed bin and obj and rebuild. (Didn't work)
  2. Unloaded the project. (It resulted in "Assets file project.assets.json not found. Run a NuGet package restore")
  3. I ran dotnet restore command via Visual Studio 2017 >> Tools >> NuGet Package Manager >> Package Manager Console.
  4. Rebuild solution. (Problem solved)
查看更多
甜甜的少女心
3楼-- · 2020-06-06 08:21

Took almost 2 days to fix. Tried VS Uninstall\re-install several times but did not work.

What finally worked for me...

Ran VS Installer repair. Due to errors, I had to manually uninstall all instances MS .NET Core SDK - 2.1xxx

Ran VS Installer repair. No errors. Remove bin and obj and rebuild.

Ran dotnet restore command on Package manager console and problem solved.

查看更多
The star\"
4楼-- · 2020-06-06 08:28

In my case, I had a project that was still set to build against a beta version of dnx. Changing it to build against the version I was using in the other projects fixed it.

查看更多
ら.Afraid
5楼-- · 2020-06-06 08:31

In my case, this is different. First check System.Runtime reference is added to your project or not. If it is added to your project, please follow the below steps.

  1. Open your Reference from your project and select System.Runtime assembly.
  2. Right click on System.Runtime and select property.
  3. Change the value of SpecificVersion from False to True.

Note : In my Case I am using Visual Studio 2019 and Project Framework Version - 4.6.2

查看更多
趁早两清
6楼-- · 2020-06-06 08:35

For me, the problem occurred when I added a new project to my solution. I re-built the solution and the errors went away.

查看更多
一纸荒年 Trace。
7楼-- · 2020-06-06 08:41

Remove bin and obj and rebuild.

查看更多
登录 后发表回答