Search code examples
c#dependenciespackagenugetazure-functions

Dependencies of packages conflicts with Newtonsoft.Json


I've an Azure Function project (.NET Framework) and I've this NuGet packages installed.

<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.4" />
<PackageReference Include="Microsoft.Graph" Version="1.17.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Swagger" Version="1.0.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

The project has also an other reference to an other created project. There I've next dependancies:

<package id="Microsoft.Azure.KeyVault" version="3.0.5" targetFramework="net472" />
<package id="Microsoft.Azure.KeyVault.WebKey" version="3.0.5" targetFramework="net472" />
<package id="Microsoft.Azure.ServiceBus" version="4.0.0" targetFramework="net472" />
<package id="Microsoft.Graph" version="1.17.0" targetFramework="net472" />
<package id="Microsoft.Graph.Core" version="1.17.0" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />

When I run a function, I got this Error:

Could not load file or assembly Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed or one of its dependencies. The system cannot find the file specified.

What's wrong with the packages? I've been searching a day for a solution but the only thing I find is that the dependencies of each packages uses an different version of Newtonsoft.Json. The Newtonsoft dependency of Microsoft.NET.Sdk.Functions must be 9.0.1, while others stand on 10.0.3 or higher.

How could I solve this?


Solution

  • newtonsoft json version is = not >=. This problem has been around for a long time, MS tracking this work here: https://github.com/Azure/azure-functions-vs-build-sdk/issues/304

    Create function v3 to avoid this error.