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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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;
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0