how to work with ASP.NET Core 2.0 and newtonsoft.json

Viewed 14373

I am doing the first of my asp.net projects, and we have settled on using asp.net core v. 2.0 - now that ms has released it. - we are using .NET 4.6 in our backed projects. but I am having some problems with using Newtonsoft.json, that apparently doesn't support the .netstandard 2.0 in the version 10.0.1 that I've installed. And for some unknown reason it will not install v.10.0.3, - I get this:

    Error   NU1202  Package Newtonsoft.Json 10.0.1 is not compatible with net461 (.NETFramework,Version=v4.6.1) / win7-x64. Package Newtonsoft.Json 10.0.1 supports:
  - net20 (.NETFramework,Version=v2.0)
  - net35 (.NETFramework,Version=v3.5)
  - net40 (.NETFramework,Version=v4.0)
  - net45 (.NETFramework,Version=v4.5)
  - netstandard1.0 (.NETStandard,Version=v1.0)
  - netstandard1.3 (.NETStandard,Version=v1.3)
  - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)    ScannerWebRemoteControl

any ideas anyone?

5 Answers

Open Integrated Terminal and run code given below

dotnet add package Newtonsoft.Json

It will download and add Newtonsoft.Json to the project (Latest version).

Newtonsoft.Json 10.0.0.3 still do not support for .NETStandard 2.0. In ASP.NET CORE Microsoft has nuget package Microsoft.AspNetCore.JsonPatch which is for .NETStandard 2.0 and makes Newtonsoft.Json available for you.

So if you have new ASP.NET CORE 2.0 project with nuget package Microsoft.AspNetCore.All it includes Newtonsoft.Json for you already (via Microsoft.AspNetCore.JsonPatch).

For .NET 4.x projects you need to add Newtonsoft.Json manually.

dotnet add package  Newtonsoft.Json -v 11.0.2

will result to :

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

Go to your .csproj file and add

  <ItemGroup>
    <DotNetCliToolReference Include="Newtonsoft.Json" Version="11.0.2"/>
  </ItemGroup>
Related