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

喜夏-厌秋 提交于 2019-12-04 09:13:37

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

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

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.

PM> Install-package Microsoft.NETCore.Portable.Compatibility

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

PM> Install-package Microsoft.NETCore.Portable.Compatibility
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!