7
votes

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.

2
The error message says "System.Runtime 4.2 is different to 4.1.2". What exact version do you have on each project?Camilo Terevinto
Are you targeting netstandard20 in the library you want to include? .NET Full and .NET Core both support .NET Standard, but direct cross-compatibility is a tad more tricky (and to be avoided if possible).Jeroen Mostert
Ensure a library is compatible with 4.7.1 and other platforms by targeting .NETStandard instead of .NETCore.Hans Passant
@JeroenMostert and hans-passant (sorry I can only tag one) thank you both. I had made the mistake of thinking .NET Core worked in its entirety with 4.7.1 (which I see now it doesn't). I managed to get past the issue by switching the .NET Core app to NET Standard.Ben Thomson

2 Answers

6
votes

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.

1
votes

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.