Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Getting following error in HttpPatch
"The JSON value could not be converted to Microsoft.AspNetCore.JsonPatch.JsonPatchDocument"

I have created an application and using following code but debug is not being focused on
[HttpPatch]
public IActionResult Patch([FromBody] JsonPatchDocument<weatherforecast> patch)
{

return Ok();
}

What I have tried:

Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson -Version 3.1.6
Posted
Updated 10-Dec-21 7:07am

Seems adding custom converters should solve it.

Reference: JsonPatchDocument Error The JSON value could not be converted to Microsoft.AspNetCore.JsonPatch.JsonPatchDocument · Issue #13938 · dotnet/aspnetcore · GitHub[^]

You'll need to update your application to reference Microsoft.AspNetCore.Mvc.Newtonsoft.Json package:

1. Install the Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package.
2. Update the project's Startup.ConfigureServices method to include a call to AddRazorRuntimeCompilation:
services
        .AddControllersWithViews()
        .AddNewtonsoftJson();


Another similar report and solve: PatchRequest fails with error The JSON value could not be converted to Microsoft.AspNetCore.JsonPatch.JsonPatchDocument · Issue #22620 · dotnet/aspnetcore · GitHub[^]
 
Share this answer
 
Comments
.NET- India 5-Aug-20 5:06am    
I have installed,"Microsoft.AspNetCore.Mvc.Newtonsoft.Json package", but which version to be installed, if i'm installing latest version i.e. "3.1.6" then giving error but installing version i.e. "3.0.2" then working fine
Sandeep Mewara 5-Aug-20 5:27am    
That would be the versin reference in the JsonPatch. It should be okay.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900