简体   繁体   中英

Migrate from /net core 2.1 to .net core 3.1

I am getting an error while migrating from .net core 2.1 to .net core 3.1

Error: The Microsoft.AspNetCore.All package is not supported when targeting .NET Core 3.0 or higher. A FrameworkReference to Microsoft.AspNetCore.The app should be used instead and will be implicitly included by Microsoft.NET.Sdk.Web.

i am getting issue with services.AddMvc(options => { options.Filters.Add(new AuthorizeFilter("default")); }).AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize) 'JsonOptions' does not contain a definition for 'SerializerSettings'

For asp.net core 3.0+,you need to install the package Microsoft.AspNetCore.Mvc.NewtonsoftJson for your version firstly,then replace

services.AddMvc()
 .AddJsonOptions(
    options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize);

with

services.AddControllersWithViews()
    .AddNewtonsoftJson(options =>
        options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize);

Refer to https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#use-newtonsoftjson-in-an-aspnet-core-30-mvc-project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM