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?

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


I was able to get my project working with Netwonsoft.Json 11.0.2 by switching to v2 of Azure Functions with .net core:

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>

In Azure the functions runtime loads a spececific (currently 11.0.1 in functions v2, 9.0.1 in functions v1) version of the Newtonsoft.Json before your function library gets loaded by the queue binding.

Any workarounds applied to make it compile will cause horrible to diagnose runtime failures if you use any function that is not binary compatible with [11.0.1] (eg, any of the new attributes used in v12) .


Running into related issue, not being able to install the Mirosoft.NET.Sdk package. Worked around this by creating a new Cloud - Azure functions project using vs2017. That project comes with the Mirosoft.NET.Sdk package version 1.0.6. Updating that to 1.0.7 actually works. Then installed Newton 9.0.1. From there on, no problems.


Need Your Help

Reorder datatable by column

crossfilter dc.js

I was wondering if there is any known way to efficiently add a "Reorder" feature to my datatables in dc.js. It would be great if my users, after having done their selection with the charts, could d...

HTML5 canvas to PDF

javascript html html5 html5-canvas

I am working in HTML5 and using canvas as a designing tool. However, I want to save my canvas in a jpeg file with a default of image/png and I want to show the preview of my canvas in a PDF.