任何想法什么会导致c#/ .net/EF/MVC5网站上的间歇性500序列化错误?

问题描述:

我有一个Azure网络应用程序.NET(4.6.1)/c#/MVC5/EF/Newtonsoft.JSON(6.0.4),它可以正常运行一个星期,然后突然出现500个错误,并且变得对每个人都无法使用。重新启动和/或回收站点使网站恢复生机。我正在努力寻找根本原因。我看到有一些线程表明应用程序池的不合理回收会导致此行为。但是,在IIS中,该站点被配置为永不回收(空闲超时= 0,并且回收计划设置为0)。有没有人经历过这个或有建议?任何想法什么会导致c#/ .net/EF/MVC5网站上的间歇性500序列化错误?

下面是错误的空话:

{"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Error getting value from 'IsCompleted' on 'Weaver.TruckScaleMgmt.Common.Models.TruckLoad'.","ExceptionType":"Newtonsoft.Json.JsonSerializationException","StackTrace":" at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.d__1b.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" at Weaver.TruckScaleMgmt.Common.Models.TruckLoad.<>c.b__71_0(TruckLoadQuality t) in C:\Users\wh741\Source\Repos\Scalehouse\Weaver.TruckScaleMgmt.Common\Models\TruckLoad.cs:line 223\r\n at System.Linq.Enumerable.WhereListIterator`1.MoveNext()\r\n at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n at Weaver.TruckScaleMgmt.Common.Models.TruckLoad.UpdateCompletedRequirements() in C:\Users\wh741\Source\Repos\Scalehouse\Weaver.TruckScaleMgmt.Common\Models\TruckLoad.cs:line 223\r\n at Weaver.TruckScaleMgmt.Common.Models.TruckLoad.get_IsCompleted() in C:\Users\wh741\Source\Repos\Scalehouse\Weaver.TruckScaleMgmt.Common\Models\TruckLoad.cs:line 335\r\n at GetIsCompleted(Object)\r\n at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)"}}}

。 。 。

更新:

我已经能够重现该问题,并认为它是一个布尔变量的序列化的问题。我还没有确定,但我相信我知道根本原因。我刚才发布的代码是不相关的根源....

UPDATE2:

确定。我已经解决了这个问题。在蓝色月亮中发生的情况在linq查询中的字段内留下空值。然而,我不知道的是,为什么这会让应用程序无法适用于所有人。有一个例子让应用程序假发给大家.....

+0

那么在'IsCompleted'和'UpdateCompletedRequirements()'中会发生什么?你有一个NRE。 –

+0

它在下面的quality.where声明上失败。不过,我认为这是一个症状。它工作正常99%的时间。 – elletek

+0

您希望从控制器方法中获得什么类型的输出?看来输出没有序列化为json。那是错误 –

我已经解决了这个问题。在蓝色月亮中发生的情况在linq查询中的字段内留下空值。然而,我不知道的是,为什么这会让应用程序无法适用于所有人。有一个例子让应用程序假发给大家.....