Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AddJsonOptions not found in ASP.NET Core 2.0

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?

like image 575
SuperJMN Avatar asked Sep 05 '17 11:09

SuperJMN


1 Answers

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;
like image 138
Set Avatar answered Oct 09 '22 01:10

Set