I've searched a lot and can't find a solution to my problem (I've seen similar runtime issues but not build).
I have a .NET 4.7.1 project (class lib) that references a .NET Core project/library. When I try to build I get the following build error:
'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
The code is simple and is just calling an async method in the .NET Core lib. A bit like:
return _dotNetCoreClass.MethodAsync();
I've tried upgrading the project so it uses ProjectReferences and not packages.config. I've installed the System.Runtime package (version 4.3.0). I've updated my project file to include the below:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
I've also installed the latest NETStandard.Librabry package but I can't get rid of the build error.
The answer is no, we cannot use . NET Framework Base Class Library in . NET Core because of compatibility issues.
You cannot directly reference a . NET Framework assembly from . NET Core or the other way round a . NET Core assembly from .
Yes, you can load . NET Framework assemblies into . NET Core 5 and 6.
I thought it was important to post the solution I found and to highlight where my understanding went wrong (thanks to @jeroen-mostert and @hans-passant for steering me in the right direction).
Not all of the .NET Core 2.0 framework is supported by .NET 4.7.1 and so some of the code we were using was not supported and hence raised a build error in application referencing the .NET Core library.
Changing the .NET Core library to use .NET Standard 2.0 (which is fine because our other .NET Core applications that will also use the library are supported by .NET Standard) and then removing and re-adding the references in the application using it solved our problems and the application now builds.
There is an issue tracked on git hub regarding the .Net Core SDK at the moment, as stated at the official .Net framework 4.7.1 disucssion:
It turns out there is an issue with .NET Core SDK, the issue is being tracked on GitHub, https://github.com/dotnet/sdk/issues/1738. By accident this issue does not repro with Visual Studio 15.5 release. If anybody would like to see if there is any workaround before the SDK issue is fixed, feel free to file an issue on https://github.com/aspnet/Mvc/issues.
For the moment, there is no way to fix your solution as 4.7.1 cannot support .Net Core.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With