Reference Loop Handling Ignore not working on Asp.Net Core 3.0 Preview 3

后端 未结 2 1026
闹比i
闹比i 2021-02-19 18:45

I have been beating my head against a wall with this one, trying to find out why it won\'t work. I haven\'t been able to find anything on why it won\'t work, so I am asking here

相关标签:
2条回答
  • 2021-02-19 19:10

    As explained in detail here as part of ASP.NET Core 3.0, the team moved away from including Newtonsoft.Json by default.

    You probably need to install Microsoft.AspNetCore.Mvc.NewtonsoftJson and use (note, I'm using .AddNewtonsoftJson() chained with .AddControllers()) something similar:

    services.AddControllers()
        .AddNewtonsoftJson(x =>
                {
                    x.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                });
    
    0 讨论(0)
  • 2021-02-19 19:19
    services.AddMvc().AddNewtonsoftJson(options=> options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
    

    https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#jsonnet-support

    0 讨论(0)
提交回复
热议问题