1

I am developing a REST web server using .net. I need to call 3rd party assemblies that was compiled against .net framework v4.0. In VS 2017 I choose the "ASP .NET Core Web Application" (.NET Core 2.1) template for my project. I try to add the 3rd party assemblies by using Project: Add->Reference... However I get yellow warning sign icons on the assemblies in the Project:Assemblies tree view.The properties page for these assemblies are all blank.

Can .net core call .net 4 assemblies? If so how do I add them to the project correctly?

Andy
  • 3,251
  • 4
  • 32
  • 53

2 Answers2

4

.NET Core cannot reference assemblies targeted .NET Framework.

But you can create assembly (Class Library) targeted .NET Standard. This assembly can be referenced both from .NET Framework 4.x and .NET Core so, you can have shared functionality in assembly that can be referenced from both .NET Framework and .NET Core.

If .NET Standard is not the case referenced assembly should be targeted .NET Core.

See additional info here - .NET Standard

Roman
  • 11,966
  • 10
  • 38
  • 47
  • Thank you. As I understand this table: assemblies created using .net 4.6.1 follows .net standard 2.0 and can therefore be used from .net core 2.0 and up. Is this correct? Does this mean that i have to wait for the 3rd party vendor to update their libraries to .net 4.6.1 before I can call them from .net core? – Andy Nov 09 '18 at 09:42
  • @Andy, it means that using .NET Framework 4.6.1 you can reference assemblies targeted .NET Standard 2.0 and lower. But .NET Framework 4.5 can reference only assemblies targeted .NET Standard 1.0. But you cannot reference assembly targeted .NET Framework 4.6.1 from .NET Core one. – Roman Nov 09 '18 at 09:46
2

No. .NET core project cannot refer legacy .NET 4.x assemblies. So the library needs to be rebuilt to support .NETCore.

Recently Microsoft has released .NET Standard to build library for both platforms, however, the assemblies remain different. It's just compiled into different targets.

Daniel Tran
  • 6,083
  • 12
  • 25
  • This is no longer true after [core2.0](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-2-0#support-for-net-framework-libraries). However, do notice that this is not suggested, and no runtime guarantee. – joe Jul 06 '21 at 04:17