Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core 5.0 error CS0012: The type 'Object' is defined in assembly 'mscorlib

In Visual Studio 2015 I have a kproj, in this project I wanted to add a reference to an assembly that is not available in any public nuget package source, so I've created my own nuget package and this way was able to add the reference to this assembly.

The problem is that now I'm getting the following exception:

ASP.NET Core 5.0 error CS0012: 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'.

Any ideas on how to overcome this?

like image 462
Rui Lima Avatar asked Dec 08 '22 05:12

Rui Lima


2 Answers

Solved it. Removed the framework "aspnetcore50" from the project.json

like image 71
Rui Lima Avatar answered May 06 '23 16:05

Rui Lima


As you wrote, removing aspnetcore50 from targeted frameworks removes the problem. However, I wanted to know why and what comes with it and I found the answer.

The difference between aspnet50 and aspnetcore50 is that they use .NET Framework 4.6 and .NET Core 5 respectively. An article What is .NET Core 5 and ASP.NET 5 within .NET 2015 Preview well explains the differences, which in short are:

When you run your ASP.NET 5 application on top of the Core-CLR and therefore .NET Core 5 framework, you’ll get an end-to-end stack optimized for server/cloud workloads which means a high throughput, very small footprint in memory and one of the most important things, side-by-side execution of the .NET Core 5 framework version (KRE or K runtime environment) related to your application, no matter what other versions of .NET might be installed in the same server or machine. Additionally, and like mentioned, you could run that web application on a web service running on Mac or Linux.

On the other hand, when you run your ASP.NET 5 application on top of the regular CLR and therefore .NET Framework 4.6 you’ll get the highest level of compatibility with existing .NET libraries and less restrictions than what you get when running on top of .NET Core 5.

It also means that to take an advantage of these great features, you need to use libraries which are .NET Core 5 compatible. If you do have an already compiled DLL, which is targetting .NET Framework, most probably it won't be compatible and you will have to use .NET Framework 4.6.

The reason for it is that .NET Core 5 doesn't contain Basic Class Library, which contains such common components like Collections, IO, LINQ, etc. The BCL components are now available as separate NuGet packages, so that you can include in your project only the pieces you need.

On how different .NET Core 5 targeted libraries are you can read in Creating multi-target NuGet Packages with vNext

like image 33
krzychu Avatar answered May 06 '23 18:05

krzychu