JsonResult(object) causes "The collection type 'Newtonsoft.Json.Linq.JToken' is not supported."

Migrate from ASP.NET Core 2.2 to 3.0

  • Add a package reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson

  • Update Startup.ConfigureServices to call AddNewtonsoftJson: services.AddMvc().AddNewtonsoftJson();


@sabiland answer helped me, small changes

  1. added in .csproj reference to NewtonsoftJson, as below

< PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />

  1. adde in Startup.cs, in method ConfigureServices, AddMvcCore

    services.AddMvcCore()
            .AddNewtonsoftJson();
    

In .NET Core 3.1 based web applications if you are getting this error, the Nuget package you need to have is the same "Microsoft.AspNetCore.Mvc.NewtonsoftJson".

The code in the ConfigureServices method in the Startup class would look like

services.AddControllersWithViews().AddNewtonsoftJson();

Refer this link