0

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.

lahimadhe
  • 374
  • 2
  • 16
Harsha Mullangi
  • 474
  • 1
  • 6
  • 27
  • There are step-by-step migration guides available at: https://learn.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-3.1&tabs=visual-studio. – juunas Feb 06 '20 at 12:10
  • @juunas thanks now 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' – Harsha Mullangi Feb 06 '20 at 16:08

1 Answers1

2

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://learn.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

Ryan
  • 19,118
  • 10
  • 37
  • 53
  • Thanks for this it solved my issue. 1more error i am getting related to cors services.AddCors(options => { options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials()); }); it says alloworigin and allowcrediantials cannot be together. If i remove any one then when i open the application it says cors has blocked – Harsha Mullangi Feb 07 '20 at 08:21
  • @Harsha Mullangi I think it is another problem about CORS problem,maybe you could use `WithOrigins()` instead https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-3.1#set-the-allowed-origins Besides, you need to put app.UseCors between app.UseRouting() and app.UseEndPoints – Ryan Feb 07 '20 at 08:24
  • but actually i want to allow all origins – Harsha Mullangi Feb 07 '20 at 08:27
  • @Harsha Mullangi Ok,in order to let more people see your new question,I suggest that you could mark the answer and open a new thread with more detailed startup code ,scenario and error info.It is hard to exactly know why you have this error – Ryan Feb 07 '20 at 08:31
  • i have opened another thread : https://stackoverflow.com/questions/60109800/cors-issue-while-migrating-form-net-core-2-2-to-net-core-3-0 – Harsha Mullangi Feb 07 '20 at 08:43