You must add a reference to assembly mscorlib, version=4.0.0

C#Linqasp.net Core.Net Core

C# Problem Overview


I'm having some trouble migrating a web project from RC1 to RC2. When I switched, I'm getting a bunch of these errors throughout the project.

> The type 'Func<,>' 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'

Looks like all of the linq functions and lambda expressions are not working.

This is what my project.json file looks like:

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "System.Linq": "4.1.0-rc2-24027"
      },
      "imports": [ "net451", "portable-net45+win8" ]
    }
  },
  "dependencies": {
    "NETStandard.Library": "1.5.0-rc2-24027",
    "Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "System.ComponentModel.Annotations": "4.1.0-*"
  }

Any ideas what this means? I've tried running dotnet restore, did not help.

C# Solutions


Solution 1 - C#

I had the same issue and adding the following package to my project.json dependencies fixed it for me:

"Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027",

This package enables compatibility with mscorlib-based PCLs.

Solution 2 - C#

In fact, the problem is an old lib that requires an asp.net 4.0 or 4.5 vesion (less than Core).

Microsoft provides a solution for it by installing the fallowing NuGet package.

> Microsoft.NETCore.Portable.Compatibility

this way you will be able to run your code with old libs.

Solution 3 - C#

Delete the .csproj.user as per in the Screenshot present in the solution folder. Unload the project from solution explorer. Reload the project and build it once. This worked for me.

Solution 4 - C#

I got this error when I created a new project using the template Class Library (.NET Standard) and ported some code into it that I wanted to re-use.

I created a new project Class Library (.NET Framework) and moved the code there instead and it worked without any issues.

Solution 5 - C#

I had this error all of a sudden while working in a unit test project. Tried the suggestions as mentioned before like unloading and reloading the project, rebuild etc. Eventually all it took was a restart of Visual Studio - Did you try to turn it off and on again :-) VS version 16.11.5

Solution 6 - C#

I don't have the rep to comment but Matt Kemp's post lead to my solution . In my case it was using a Class Library(.Net Standard) instead of Android Class Library (Xamarin)

Solution 7 - C#

mscorlib reference is added by default, but it seems to be a visual studio reference issue. I have deleted my project and created new one then it worked fine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpainiyffView Question on Stackoverflow
Solution 1 - C#Morteza ManaviView Answer on Stackoverflow
Solution 2 - C#Daniel SantosView Answer on Stackoverflow
Solution 3 - C#Ashwathy P KumarView Answer on Stackoverflow
Solution 4 - C#Matt KempView Answer on Stackoverflow
Solution 5 - C#DeMakiView Answer on Stackoverflow
Solution 6 - C#Brandon ShafferView Answer on Stackoverflow
Solution 7 - C#RamView Answer on Stackoverflow