我有另一个ASP.NET Core 2/Angular 2应用程序使用的ASP.NET Core 2 API C#项目.我已经将API项目MVC服务JSON选项配置ReferenceLoopHandling为Ignore例如
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
Run Code Online (Sandbox Code Playgroud)
但是,当我运行我的应用程序时,我仍然从我的一个HTTP GET方法中得到"检测到自我引用循环..."错误.
在调试模式下,如果我在序列化结果之前暂停方法并手动运行序列化,例如
?Newtonsoft.Json.JsonConvert.SerializeObject(
myDataObject,
new Newtonsoft.Json.JsonSerializerSettings
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
})
Run Code Online (Sandbox Code Playgroud)
数据按预期序列化而没有错误.
为什么不将服务配置应用于此方法?