Using .Net Core dll in standard .net Console app

-2

I have built a class library in VS 2017 using .NET Core 2.1. Now, I want to use that dll in a standard console app built in .NET framework 4.6.2.

When I refer to the .NET Core dll in the console app, I am getting this error:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Marketo_Console.Program.Main(String[] args)

How to resolve this? How can I use a .NET Core dll in a standard console app?

c#
.net
dll
.net-core
asked on Stack Overflow Nov 14, 2018 by Waheed • edited Nov 14, 2018 by Tim Diggins

1 Answer

2

How to resolve this?

You cannot. At least not directly.

  • .NET Core can run assemblies targeting either .NET Core itself or .NET Standard
  • .NET Framework can run assemblies targeting either .NET Framework itself or .NET Standard

So there is no way to bring two assemblies that target Full Framework and Core respectively together. Not in Core and not in full framework. (You might be able to find hacks and "but for me this works" solutions all over the place, but they are super brittle exceptions for their specific use case).

You could switch your target framework of the .NET Core assembly to either .NET Framework, or to .NET Standard, or you could give multiple target frameworks to build a Nuget package that supports .NET Core and full framework.

But if you need a .NET Core assembly and a .NET Framework application, you cannot use them together that way.

answered on Stack Overflow Nov 14, 2018 by nvoigt

User contributions licensed under CC BY-SA 3.0