.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;
});

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-11-09 高等数学 第三章 导数与微分 柳重堪 P10-P19 10个视频
2021-11-09 How to specify data attributes in razor, e.g., data-externalid="23151" on @this.Html.CheckBoxFor(...)
2021-11-09 jQuery.validator.unobtrusive.adapters.addMinMax round trips, doesn't work in MVC3
2021-11-09 Debug a script that sits in a partial view
2021-11-09 Windows Services Recovery option doesn't work ... or I don't understand it RRS feed
2017-11-09 chrome的F12的inspect使用
2017-11-09 Macro expressions in kentico
点击右上角即可分享
微信分享提示