使用.NET Core 3预览4,F# ASP.NET MVC项目的"API“模板无法构建。这对模板没有任何改变。

这是失败的代码:
type Startup private () =
member this.ConfigureServices(services: IServiceCollection) =
// Add framework services.
services.AddControllers().AddNewtonsoftJson() |> ignore有错误
...\Startup.fs(23,35):error FS0039:未定义字段、构造函数或成员“AddNewtonsoftJson”。也许您想要下列之一: AddNewtonsoftJsonProtocol
它似乎有即将发生的变化 -它只是正在工作和不可用的现在?
发布于 2019-06-11 08:42:46
为了将ASP.NET Core3.0切换回使用JSON.NET,您需要引用NuGet包。它将包含AddNewtonsoftJson扩展方法。
在C#中,如下所示:
services.AddControllers()
.AddNewtonsoftJson();因此,假设我对F#有足够的了解,如果您在项目中引用了包,那么您的调用将是正确的。
发布于 2021-09-11 05:20:26
添加包: Microsoft.AspNetCore.Mvc.NewtonsoftJson
包装详细信息:https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJson
调用AddNewtonsoftJson()扩展方法,如下所述
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews().AddNewtonsoftJson();
}发布于 2020-09-18 11:30:09
对我来说,这有帮助:
services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
https://stackoverflow.com/questions/55787018
复制相似问题