4

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?

4 Answers 4

5

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

1
  • 1
    It solved the problem in my case too. Why does it solve the problem? Any ideas?
    – krzychu
    Commented Apr 18, 2015 at 13:13
5

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

4

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.