.Net Core 3.0 possible object cycle was detected which is not supported

.Net Core 3.0 possible object cycle was detected which is not supported

 

回答1

Instead of using NewtonsoftJson I used System.Text.Json.Serialization

For .Net Core 3.1

In Startup.cs

 public void ConfigureServices(IServiceCollection services)
 {
    ..........
    .......

    services.AddControllers().AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
        options.JsonSerializerOptions.WriteIndented = true;
    });
 }

For .Net 6

In Program.cs

builder.Services.AddControllers().AddJsonOptions(options => 
{ 
    options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
    options.JsonSerializerOptions.WriteIndented = true;
});

 

posted @ 2022-11-09 12:54  ChuckLu  阅读(32)  评论(0)    收藏  举报