Azure-functions-vs-build-sdk: Please update the Newtonsoft.Json (= 9.0.1) dependency for higher version ASAP.

Created on 3 Dec 2017  路  13Comments  路  Source: Azure/azure-functions-vs-build-sdk

Restoring packages for D:xxxFunctionApp1.csproj...
Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue.
FunctionApp1 -> Google.Cloud.Storage.V1 2.0.0 -> Google.Apis.Storage.v1 1.27.1.881 -> Google.Apis.Auth 1.27.1 -> Google.Apis.Core 1.27.1 -> Newtonsoft.Json (>= 10.0.2)

FunctionApp1 -> Microsoft.NET.Sdk.Functions 1.0.6 -> Newtonsoft.Json (= 9.0.1).
Package restore failed. Rolling back package changes for 'FunctionApp1'.

Most helpful comment

See comments on:
https://docs.microsoft.com/en-us/dotnet/framework/security/downloading-the-json-web-token-handler-package

Created an Azure function project using Visual Studio -- then try to install JWT Token Handler from NuGet as per instructions on this page.

Result:

NU1107: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue.

test1 -> System.IdentityModel.Tokens.Jwt 5.2.1 -> Newtonsoft.Json (>= 10.0.1)
test1 -> Microsoft.NET.Sdk.Functions 1.0.8 -> Newtonsoft.Json (= 9.0.1).

Now what?

All 13 comments

@amitchaudhary take a look at #107

Just add the Newtonsoft.Json = 10.0.2 explicitly in your csproj. That should fix this. The setting here is on purpose

How is "Just add the Newtonsoft.Json = 10.0.2" an answer?
Microsoft.NET.Sdk.Functions 1.0.6 (and newer) requires Newtonsoft.Json version 9.0.1 only. And if you have other dependencies requiring > 9.0.1, then we're out of luck because the Azure Functions SDK doesn't run with the later versions of Newtonsoft. At least I'd love to verify this.

I'm totally stuck on this and looking for a workaround.

Adding Newtonsoft.Json 10.0.2 to your csproj is the workaround.

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.8" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
  </ItemGroup>

Are you saying that is not working for you?

No, it doesn't work for me.
My .csproj looks like:

...
   <ItemGroup>
    <PackageReference Include="BinanceDotNet" Version="4.2.4" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Bittrex.Net" Version="2.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="PoloniexSharp" Version="1.0.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.8" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
  </ItemGroup>
...

And I am getting the exception:

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.":"Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"

And it looks like that exception is being thrown from the BinanceDotNet dependency.
Any ideas?

See comments on:
https://docs.microsoft.com/en-us/dotnet/framework/security/downloading-the-json-web-token-handler-package

Created an Azure function project using Visual Studio -- then try to install JWT Token Handler from NuGet as per instructions on this page.

Result:

NU1107: Version conflict detected for Newtonsoft.Json. Reference the package directly from the project to resolve this issue.

test1 -> System.IdentityModel.Tokens.Jwt 5.2.1 -> Newtonsoft.Json (>= 10.0.1)
test1 -> Microsoft.NET.Sdk.Functions 1.0.8 -> Newtonsoft.Json (= 9.0.1).

Now what?

Hi Ahmed @ahmelsayed, the others are right. A few months ago I did the same thing you recommended in this thread and, as a result, I was getting weird errors at runtime. For example my code trying to catch Newtonsoft Json serialization exception wasn't catching the exceptions of the same type (same namespace and class name) but coming from an older version of the library. I had to downgrade to Newtonsoft.Json 9.0.1

@fabiocav has been working on removing that requirement for v2 apps. I'll let him comment on that.

Again, the limitation doesn't come from this repo. The runtime takes dependency on that version of Newtonsoft.Json. The [9.0.1] defined here is to protect you from getting these runtime errors as mentioned in the README

This is where the issue it tracked https://github.com/Azure/azure-functions-host/issues/992

For V2, we're lifting this restriction. In V1, the recommendation from @ahmelsayed should work as long as use of the SDK is scoped to the function (for scenarios like the above, if an exception type from SDK is thrown by working with runtime logic, that would lead to similar type mismatch issues)

Thanks Ahmed and Fabio, it's great to hear that this limitation won't exist in V2! And sorry for commenting in the wrong repository. Using a slightly older version of the two libraries wasn't a problem in our case, but thanks for the information.

@fabiocav @ahmelsayed Just letting you know that your recommended fix is not working. I have a separate class lib using Microsoft.Azure.Devices (IoT) which works fine outside Microsoft.NET.Sdk.Functions, but fails when used in an Azure Function:

[A]Newtonsoft.Json.Linq.JObject cannot be cast to [B]Newtonsoft.Json.Linq.JObject. Type A originates from 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context 'Default' at location 'C:\Users\wmmih\AppData\Local\AzureFunctionsTools\Releases\1.0.12.1\cli\Newtonsoft.Json.dll'. Type B originates from 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in the context 'LoadFrom' at location 'C:\@GIT\axians\microServiceBus.functions\microservicebus.functions\bin\Debug\net462\bin\Newtonsoft.Json.dll'.

(PackageReference is used on both projects)

When is V2 scheduled?

Hey guys, just so you know, releasing production ready functionality that doesn't work and providing no support isn't a very good solution. Saying, It's fixed in V2 which is still in preview, and you've broken several times isn't a fix. Stating, just reference a higher level version of the nuget package isn't working either; that's not a solution and it causes runtime errors. Can you please actually support your broken code?

This is the wrong repo to discuss this issue. Use this https://github.com/Azure/azure-functions-host/issues/992 for further discussion.

Closing the thread.

Was this page helpful?
0 / 5 - 0 ratings