【发布时间】:2015-01-28 03:57:30
【问题描述】:
我正在将 Hangfire 集成到我的项目中。我从 BackgroundJob.Enqueue 中的 Newtonsoft.Json.Serialization 得到了一个例外,如下所示。谁能告诉我如何解决这个问题?
检测到类型为“ASP.global_asax”的属性“ApplicationInstance”的自引用循环。路径'NamingContainer.Page.ModelBindingExecutionContext.HttpContext.ApplicationInstance.Context'。
在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, Object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter 编写器,对象值,JsonContainerContract 合同,JsonProperty 成员,JsonProperty 属性,JsonContract& memberContract,Object& memberValue) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer,对象值,JsonContract valueContract,JsonProperty 成员,JsonContainerContract containerContract,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) 在 Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter,对象值,类型 objectType) 在 Newtonsoft.Json.JsonConvert.SerializeObject(对象值、类型类型、格式化格式、JsonSerializerSettings 设置) 在 Hangfire.Common.Job.GetArguments(MethodCallExpression callExpression) 在 Hangfire.Common.Job.FromExpression(Expression
1 methodCall) at Hangfire.BackgroundJobClientExtensions.Create(IBackgroundJobClient client, Expression1 methodCall, IState 状态) 在 Hangfire.BackgroundJobClientExtensions.Enqueue(IBackgroundJobClient 客户端,Expression1 methodCall) at Hangfire.BackgroundJob.Enqueue(Expression1 methodCall)
【问题讨论】:
-
你应该使用 JsonSerializerSettings。