2
votes

After updating and including some NuGet packages, I now get many compile errors similar to:

The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

I looked at You must add a reference to assembly mscorlib, version=4.0.0 but I'm not running .Net core - this is an ASP.NET MVC, .Net Framework 4.7.2 Project.

There is no project.json to update. I already included the Microsoft.NETCore.Portable.Compatibility NuGet package to no effect.

What is causing this, and how can I fix it?

3
Try restarting all instances of Visual Studio, cleaning and building the solution, and running Update-Package -Reinstall in the NuGet console. You may need to try another clean + build after running Update-Package -Reinstall. - Lews Therin
Also, sometimes checking in the /packages folder into source control can cause issues like this. Remove it from source control and re-download the project and try again (make sure the NuGet restore happens). - Lews Therin
@LewsTherin No change (though the Reinstall did throw a warning, unsure if that's related - "Directory 'Content' is not empty. Skipping..."). My packages folder is part of the .gitignore. - Sarov
@LewsTherin Tried deleting the local repo, re-cloning, and doing it again... This time it worked. No idea what the problem was, but it's gone now. - Sarov

3 Answers

1
votes

Right-Click on your project and click Clean Solution in Visual Studio, and then try building it again. Solves the problem most of the time for me. Or else, in case you copy-pasted a class from somewhere else, try creating a new class in your project and instead, copy-paste the code within the other class instead of just copying the class itself.

0
votes

I also faced the same issue, I got this when I was trying to install EntityFramework. Code Clean-Up worked for me. Go to analyze and then try to run code cleanup using both profiles.

0
votes

For completeness's sake, I'll include the fix that actually worked for me as an answer.

Just delete the repo, re-clone, and try again.