Search code examples
c#.net-core.net-framework-version

Consume .NET Framework class library in .NET Core project


I have a .NET Core web api project (further in text - the api), and also I have a .NET Framework library (the library). I want have an ability to call the library from the api. How can I reach this? I googled for a while, but has found no useful article or example.

I MUST implement the library on .NET Framework, because it uses some unique and alternativeless references.


Solution

  • I MUST implement the library on .NET Framework, because it uses some unique and alternativeless references.

    If that's the case, then you must host it in a process that loads the .NET Framework Common Language Runtime.

    And the only interop between .NET Framework CLR and .NET Core CLR is the normal IPC mechanisms. You can't use .NET Remoting or MarshalByRefObjects like you could across AppDomains in .NET Framework.

    Since you're already hosting a web API, the natural thing is probably to host a separate web API on the .NET Framework to host your library. Alternatively you could write a .NET Framework COM component to wrap your library and access it from COM Interop from .NET Core on Windows. And, of course, you can always just build a .NET Framework .exe and launch it from .NET Core with Process.Start.