Anderson Matos
Anderson Matos

Reputation: 3147

Call method from regular ClassLibrary within .NET Core?

Background

We're changing a few items on our project and I've stumbled on an integration issue.

There are some 3rd. party DLLs written on regular ClassLibrary (.NET 4.0) and our project is now on .NET Standard + AspNet Core. We must update the whole infraestructure while keeping everything working.

Structure

App_1 calls SomeFramework which then calls SomeExternal.
App_2 also calls SomeFramework which then calls SomeExternal.

This is done to prevent direct calls to SomeExternal. This is a requirement from the project which cannot be changed.

Problem

How can I reference SomeExternal into SomeFramework?
I've tried direct assembly link (Add References > Assemblies > Search) but SomeExternal fails to load.

I've set the whole project to x64 or x86 (instead of AnyCPU) but nothing changed.

We're using VS2017 15.5.5, .NET 4.7.1 and .NET Core SDK 2.1.4.

Upvotes: 1

Views: 2365

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239400

.NET Core fully supports .NET Standard 2.0, which itself has a wide-enough API footprint that Microsoft has added native support for .NET Framework libraries. In other words, if you're running .NET Core 2.0+, you can add a reference to any .NET Framework library you want.

You will, however, get a warning. The warning, though, is simply to let you know that while you may be able to fully utilize the library, there is a possibility that it uses APIs which are not supported. It's on you to test and verify that everything works correctly, and then you can safely suppress the warning, if you like.

Mostly, those unsupported APIs at this point would resolve around Windows-specific functionality. Since .NET Core and .NET Standard are cross-platform, an API that is only for Windows would not be among the API footprints of either. However, even then, there is the Microsoft.Windows.Compatibility NuGet which extends .NET Standard to support some of those missing APIs. However, this NuGet is only intended for migrating an application to .NET Standard/.NET Core, not as a long-term solution. The goal should still be to move away from this unsupported APIs to ones that actually are supported and cross-platform.

You should also employ the API Analyzer, which will call out usages of deprecated and unsupported APIs both in old code and new. That way, as you're working, you can see things that still need to be ported and be reminded if you revert back to using something that you shouldn't.

Upvotes: 2

Related Questions