Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version conflict caused by Microsoft.NET.Sdk.Functions

I'm having issues with a project referencing 2 packages that then reference Newtonsoft.Json but both at different versions. I'm using the nuget package of Refit and Microsoft.NET.Sdk.Functions. When I try to build the solution I get the following error:

C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. \r C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607:  noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) \r C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607:  noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1). 

Now if I do what it says and reference the package directly from my project I get another error when building:

C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Newtonsoft.Json   Writing C:\Users\joebloggs\AppData\Local\Temp\tmp7250.tmp info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. log  : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj... info :   CACHE http://www.myget.org/F/azure-appservice/api/v2/FindPackagesById()?id='Newtonsoft.Json' info :   CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Newtonsoft.Json' info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. info : PackageReference for package 'Newtonsoft.Json' version '10.0.3' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.    noddy.Api -> C:\dev\noddy\noddy-api\src\noddy.Api\bin\Debug\net461\bin\noddy.Api.dll C:\Users\joebloggs\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]  Build FAILED.  C:\Users\joebloggs\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]     0 Warning(s)     1 Error(s)  Time Elapsed 00:00:03.05  C:\dev\noddy\noddy-api\src\noddy.Api> 

I've tried to add in assembly redirects but seems these are ignored.

I've also tried to remove all the packages and add them back in one by one and still no joy:

C:\dev\noddy\noddy-api\src\noddy.Api>dotnet remove package refit info : Removing PackageReference for package 'refit' from project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet remove package Microsoft.NET.Sdk.Functions info : Removing PackageReference for package 'Microsoft.NET.Sdk.Functions' from project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet remove package Newtonsoft.Json info : Removing PackageReference for package 'Newtonsoft.Json' from project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Microsoft.NET.Sdk.Functions   Writing C:\Users\joebloggs\AppData\Local\Temp\tmp1F1B.tmp info : Adding PackageReference for package 'Microsoft.NET.Sdk.Functions' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. log  : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj... info :   CACHE http://www.myget.org/F/azure-appservice/api/v2/FindPackagesById()?id='Microsoft.NET.Sdk.Functions' info :   CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NET.Sdk.Functions' info : Package 'Microsoft.NET.Sdk.Functions' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. info : PackageReference for package 'Microsoft.NET.Sdk.Functions' version '1.0.2' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package refit   Writing C:\Users\joebloggs\AppData\Local\Temp\tmp39D7.tmp info : Adding PackageReference for package 'refit' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. log  : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj... info :   CACHE http://www.myget.org/F/azure-appservice/api/v2/FindPackagesById()?id='refit' info :   CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='refit' error: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. error:  noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) error:  noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1). info : Package 'refit' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. info : PackageReference for package 'refit' version '4.0.1' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue. \r C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607:  noddy.Api (>= 1.0.0) -> Refit (>= 4.0.1) -> Newtonsoft.Json (>= 10.0.3) \r C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj : error NU1607:  noddy.Api (>= 1.0.0) -> Microsoft.NET.Sdk.Functions (>= 1.0.2) -> Newtonsoft.Json (>= 9.0.1).  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet add package Newtonsoft.Json   Writing C:\Users\joebloggs\AppData\Local\Temp\tmp8B13.tmp info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. log  : Restoring packages for C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj... info :   CACHE http://www.myget.org/F/azure-appservice/api/v2/FindPackagesById()?id='Newtonsoft.Json' info :   CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='Newtonsoft.Json' info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'. info : PackageReference for package 'Newtonsoft.Json' version '10.0.3' added to file 'C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj'.  C:\dev\noddy\noddy-api\src\noddy.Api>dotnet build Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.    noddy.Api -> C:\dev\noddy\noddy-api\src\noddy.Api\bin\Debug\net461\bin\noddy.Api.dll C:\Users\joebloggs\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]  Build FAILED.  C:\Users\joebloggs\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\dev\noddy\noddy-api\src\noddy.Api\noddy.Api.csproj]     0 Warning(s)     1 Error(s)  Time Elapsed 00:00:03.05  C:\dev\noddy\noddy-api\src\noddy.Api> 

Also there is nothing magic going off in my csproj:

<Project Sdk="Microsoft.NET.Sdk">   <PropertyGroup>     <TargetFramework>net461</TargetFramework>   </PropertyGroup>   <ItemGroup>     <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.2" />     <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />     <PackageReference Include="refit" Version="4.0.1" />   </ItemGroup>   <ItemGroup>     <Reference Include="Microsoft.CSharp" />     <Reference Include="System.Configuration" />   </ItemGroup>   <ItemGroup>     <None Update="host.json">       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>     </None>     <None Update="local.settings.json">       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>     </None>     <None Update="proxies.json">       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>     </None>   </ItemGroup> </Project> 

Any one got any ideas of how to fix this issue?

like image 613
Kevin Smith Avatar asked Sep 06 '17 11:09

Kevin Smith


People also ask

What is Microsoft .NET SDK used for?

The software development kit (SDK) includes everything you need to build and run . NET applications, using command-line tools and any editor (like Visual Studio). Runtime (Windows) The runtime includes everything you need to run .

What is .NET SDK version?

NET SDK is a set of libraries and tools that allow developers to create . NET applications and libraries. It contains the following components that are used to build and run applications: The .


1 Answers

Latest Update

The lock was removed and the version upgraded to 11.0.2 in July 2019. Upgrading to 12 can still cause some deployment issues


Unfortunately, this is a known bug of the Azure Functions MSBuild project. All the release versions have a hard-coded dependency on Json.NET 9.0.1. The only workaround reported is to downgrade to the 1.0.0-alpha6 version.

The lack of package summary and description, as well as the lack of documentation in the Github project are a clear sign that this is a work in progress.

Assuming you do need it, you can try to clone the repo, change the dependency in .csproj and rebuild the package.

In the meantime, you should probably add a comment to the issue, explaining that you are affected as well.

To fix this, Line 39 of csproj should change from :

<PackageReference Include="Newtonsoft.Json" Version="[9.0.1]" /> 

to

<PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> 

There other exact version dependencies on beta versions of Microsoft.Azure.WebJobs packages

Update November 2018

The repo's Readme was updated on March 31 2018 with an FAQ that explains why the Json.NET version is locked and how to handle this :

Q: I need a different Newtonsoft.Json version. What do I do?

A: Add the version you need to your csproj. For example to use 11.0.2 add this to your csproj

<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> 

Q: Why is Newtonsoft.Json locked in the first place?

A: The version of Newtonsoft.Json is locked to match the version used by the functions runtime

There's a long discussion on the (now locked) issue that explains that unlocking the version would only delay problems until deployment

Update September 2019

The Json.NET version is no longer locked and the referenced version is 11.0.2. The PR was merged in July 2019. As the comments show though, this simply removes the compile-time restriction. It's still possible to get deployment problems though, like this one

like image 55
Panagiotis Kanavos Avatar answered Oct 06 '22 23:10

Panagiotis Kanavos