Search code examples
c#asp.net.net-coreasp.net-core-webapistartup

I can not use the 'services.AddControllers().AddNewtonsoftJson()'


I'm in Net core 3.1 and I'm trying to use AddNewtonsoftJson()

I'm getting:

"IMvcBuilder' does not contain a definition for 'AddNewtonsoftJson' and no accessible extension method 'AddNewtonsoftJson' accepting a first argument of type 'IMvcBuilder' could be found (are you missing a using directive or an assembly reference?)"

This is what I write in my ConfigureService:

services.AddControllers().AddNewtonsoftJson();

I already have installed NewtonSoft in my startup project.


Solution

  • You need also to install Microsoft.AspNetCore.Mvc.NewtonsoftJson which contains corresponding extension methods, as written in the docs .