How to fix 'IMvcBuilder' does not contain a definition for 'AddNewtonsoftJson'

This post shows you how to fix 'Error CS1061 '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?)'

To solve the problem you can right click on your project, then select Manage Nuget Packages => Install

Microsoft.AspNetCore.Mvc.NewtonsoftJson

Finally, you can call

services.AddControllers().AddNewtonsoftJson();