如果您在使用 ASP.NET Core 6 并遇到了以下错误:
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.Infrastructure.IHttpRequestBodyWriters' while attempting to activate 'Microsoft.AspNetCore.Mvc.Infrastructure.ResponseBodyWriterFactory'
这通常是由于在 Startup.cs 文件中缺少以下代码所导致的:
services.AddControllers().AddNewtonsoftJson(); // 添加这行代码
在这里使用 AddNewtonsoftJson 可以为您的应用程序添加对 NewtonSoft.Json 序列化程序的支持。