AddJsonOptions not found in ASP.NET Core 2.0

2020-02-13 09:47发布

I'm migrating my ASP.NET 1.1 project to 2.0:

Inside the Setup class, under the Configure method override I have:

services.AddMvc()
    .AddJsonOptions(options =>
        options.SerializerSettings.Converters.Add(new StringEnumConverter())
    );

The AddJsonOptions method is missing.

What happened to it? How can I get the same functionality?

1条回答
▲ chillily
2楼-- · 2020-02-13 09:54

AddJsonOptions is defined in Microsoft.AspNetCore.Mvc.Formatters.Json nuget package.

If your project has a dependency to Microsoft.AspNetCore.All metapackage (in your .csproj: <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0"/> ) then you already have it. Otherwise, you may need to add that package directly.

After that do:

  • dotnet restore
  • check that you have using Microsoft.Extensions.DependencyInjection;
查看更多
登录 后发表回答