参考循环处理忽略在Asp.Net Core 3.0 Preview 3上不起作用 [英] Reference Loop Handling Ignore not working on Asp.Net Core 3.0 Preview 3

查看:86
本文介绍了参考循环处理忽略在Asp.Net Core 3.0 Preview 3上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在用这个把头撞在墙上,试图找出为什么它不起作用.我至今无法找到任何有关它为什么行不通的信息,所以我在这里问.

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.

我有一个在Asp.Net Core 3.0 Preview 3上运行的控制台应用程序.

I have a console application that is running on Asp.Net Core 3.0 Preview 3.

在该项目上,我遇到了一个Json循环问题,我知道可以通过将启动"中的引用循环处理"设置为忽略"来解决.但是,我只能在.AddJsonOptions()中找到有关设置它的信息,在Asp.Net Core 3.0中似乎没有.

On this project I am getting a Json loop problem, which I know I can fix with setting the Reference Loop Handling in Startup to Ignore. However, I could only find information on setting it inside the .AddJsonOptions(), which doesn't appear to be in Asp.Net Core 3.0.

我去了如何从2.1迁移到3.0的文档,发现

I went to the documentation for how to migrate from 2.1 to 3.0 and I found this

即使在相应地更改了我的代码之后

Even after changing my code accordingly

services.AddMvc()
     .AddNewtonsoftJson(
          options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }
      );

我仍然收到错误消息:检测到类型为[[模型名称]]的属性'[插入类名称]'的自引用循环."

I still get an error saying: "Self referencing loop detected for property '[insert class name]' with type '[model name]'."

我还能在哪里设置Json忽略循环引用?

Where else can I set Json to ignore the loop reference?

或者我该怎么做才能做到这一点?

Or what can I do to make this work?

非常感谢您

推荐答案

services.AddMvc().AddNewtonsoftJson(options=> options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

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

这篇关于参考循环处理忽略在Asp.Net Core 3.0 Preview 3上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆