.NET Core 3预览4:"AddNewtonsoftJson"未定义 [英] .NET Core 3 preview 4: 'AddNewtonsoftJson' is not defined

查看:1358
本文介绍了.NET Core 3预览4:"AddNewtonsoftJson"未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用.NET Core 3预览版4,F#ASP.NET MVC项目的"API"模板无法生成.这对模板没有任何更改.

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.

这是失败的代码:

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

有错误

... \ Startup.fs(23,35):错误FS0039:未定义字段,构造函数或成员'AddNewtonsoftJson'.也许您需要以下之一:AddNewtonsoftJsonProtocol

...\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?

推荐答案

为了将ASP.NET Core 3.0切换回使用JSON.NET,您需要引用

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.

在C#中,它看起来像这样:

In C#, this would look like this:

services.AddControllers()
    .AddNewtonsoftJson();

因此,假设我对F#理解得足够多,那么我想说,如果您在项目中引用了该程序包,那么您的调用将是正确的.

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.

这篇关于.NET Core 3预览4:"AddNewtonsoftJson"未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆