.NET Core 3 preview 4: 'AddNewtonsoftJson' is not defined

五迷三道 提交于 2020-08-19 05:57:12

问题


Using .NET Core 3 preview 4, the "API" template for a F# ASP.NET MVC project fails to build. This is without any changes to the template whatsoever.

This is the code that fails:

type Startup private () =
    member this.ConfigureServices(services: IServiceCollection) =
        // Add framework services.
        services.AddControllers().AddNewtonsoftJson() |> ignore

With error

...\Startup.fs(23,35): error FS0039: The field, constructor or member 'AddNewtonsoftJson' is not defined. Maybe you want one of the following: AddNewtonsoftJsonProtocol

It seems that there are changes coming for this - is it just being worked on and unusable right now?


回答1:


In order to switch ASP.NET Core 3.0 back to use JSON.NET, you will need to reference the Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package. That will contain the AddNewtonsoftJson extension method.

In C#, this would look like this:

services.AddControllers()
    .AddNewtonsoftJson();

So assuming that I understand enough of F#, I would say that your call would be correct if you have the package referenced in your project.



来源:https://stackoverflow.com/questions/55787018/net-core-3-preview-4-addnewtonsoftjson-is-not-defined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!