frank
frank

Reputation: 1302

Why an Dot Net Core Class Library or Console App Can Reference A Dot Net 4.6 Class Library?

I searched on Google and get some knowledge as below:

  1. Net Core and Net Framework (4.6.*) are two different implementations of the .NET runtime, they are platform
  2. .NET Standard defines a set of APIs that .NET platforms agree to implement and it is NOT a runtime

So I fully understand both NET Core console app and NET 4.6.1 console app can add reference to a certain .NET Standard Library as long as they are compatible.

What confused me is that

  1. An Net Core 1.1 console app can add reference of a 4.6.1 class library and run well
  2. An 4.6.1 console app can NOT add reference to an Net Core 1.1 class library.

I tested this with VS2017 15.3, and I know there are some discuss about how to add reference to 4.6.1 dll in an Core app, but all of them are talked about old core project (that uses project.json) which is obsolete since the official RTM VS2017. Why 1 is ok while 2 is not possible?

Thanks

Upvotes: 0

Views: 552

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100791

This was done to enable re-using existing projects and pre-built assemblies (dll files) provided they only use API (types, methods etc.) that also is in .NET Standard 2.0.

You are right in that it seem counterintuitive and "should not work". However, there is a small compatibility layer to load the .NET Framework assemblies but they may fail if they use unsupported API, so it is dangerous to use this compatibility mechanism and one should check the project/assemblies before doing so using the .NET Portability Analyzer.

Upvotes: 0

Related Questions