Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 228
painiyff Avatar asked May 26 '16 18:05

painiyff


People also ask

How do I add a reference to the system core?

Right-click on the project node again and select Edit. In the editor, copy another reference line (for example, the one for "System") and paste it below the original reference inside the same ItemGroup. Change the reference name to "System. Core".

What is MSCorLib DLL?

NET Framework, MSCorLib. dll was an acronym for Microsoft Common Object Runtime Library. Once ECMA started to standardize the CLR and parts of the FCL, MSCorLib. dll officially became the acronym for Multilanguage Standard Common Object Runtime Library."

How do I install MSCorLib DLL?

Method 1: Download Mscorlib.dll to PC from our site. Copy the file to the program install directory after where it is missing the DLL file. Or move the DLL file to the directory of your System (C:\Windows\System32, and for a 64 bit in C:\Windows\SysWOW64\). Now you need to reboot the computer.


4 Answers

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.

like image 169
Morteza Manavi Avatar answered Oct 22 '22 22:10

Morteza Manavi


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.

like image 26
Daniel Santos Avatar answered Oct 22 '22 23:10

Daniel Santos


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.

like image 11
Ashwathy P Kumar Avatar answered Oct 22 '22 21:10

Ashwathy P Kumar


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.

like image 4
Matt Kemp Avatar answered Oct 22 '22 21:10

Matt Kemp