3

I have a standard WPF application developed in .Net framework 4. Now, my client wants a website which I am planning to develop using .Net Core. In order to share the business logic, I need to move the database along business layer to a separate project and here I am planning to use .Net Core. So, all the layers i.e. Data/ Business/ API will be re-written using latest version of .Net Core.

Would I be able to reference business layer written in .Net Core from WPF (.Net Framework 4) project?

Any pointers will be highly appreciated.....

Anil C
  • 1,045
  • 3
  • 16
  • 38

2 Answers2

4

You should implement the common functionality in a .NET Standard library. You will then be able to reference this assembly from all apps that are compatible with the version of the .NET Standard that your common project targets.

The various .NET implementations target specific versions of .NET Standard and the following table on MSDN lists all versions of .NET Standard and the platforms supported: https://learn.microsoft.com/en-us/dotnet/standard/net-standard.

The latest version of .NET Core (currently 2.0 at the time of writing) implements .NET Standard 2.0. The oldest version of the .NET Framework that implements .NET Standard 2.0 is 4.6.1. This means that your WPF app should target 4.6.1 to be able to consume a .NET Standard 2.0 assembly.

.NET Core 1.0 and .NET Framework 4.5 support .NET Standard 1.0.

The .NET Framework 4.0 doesn't support any version of .NET Standard though so you should re-target your WPF app against (at least) .NET Framework 4.5.

mm8
  • 163,881
  • 10
  • 57
  • 88
2

Would I be able to reference business layer written in .Net Core from WPF (.Net Framework 4) project?

The answer is yes. You can try it: In Visual Studio create a WPF application project and a .NET Standard library project and then add a reference from the application project to the library project.

There will be NuGet packages that you cannot reference in your .NET Standard project because they only support full .NET Framework but most popular NuGet packages can be referenced from a .NET Standard project. Your question is also tagged [entity-framework-6]. If you want to use Entity Framework from a .NET Standard project you will have to use Entity Framework Core as Entity Framework 6 requires the full framework.

You should probably create a quick spike to determine if you can build your application how you intend to.

Martin Liversage
  • 104,481
  • 22
  • 209
  • 256
  • It should be noted here that EF Core is far away from being feature equal with EF 6, so that the OP would carefully have to analyze the used APIs and features before he decides. Alternatively its always possible to run ASP.NET Core on .NET Framework (for the time being) until a specific important feature is available on .NET Core – Tseng Oct 17 '17 at 12:05
  • I have upgraded my WPF based application to .Net framework 4.6 and added references of various layers which are developed using .Net Standard 1.3 version. Now, I am facing another error w.r.t. Microsoft's Dependency Injection library. Error details are as under - Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.Any suggestions where is the problem. – Anil C Nov 03 '17 at 06:07
  • @AnilC: Have a look at this question with answers: https://stackoverflow.com/questions/46051831/could-not-load-file-or-assembly-system-security-cryptography-algorithms-versio You need to add binding redirects to your WPF project. – Martin Liversage Nov 03 '17 at 07:54