我有个奇怪的问题。我有Windows服务。服务在100多台计算机上运行正常。但是在其中的几天(甚至一个月)之后,它开始抛出这样的异常:
System.InvalidOperationException:'Y‘上的'X’属性不能设置为'System.String‘值。必须将此属性设置为‘System.Int 32’类型的非空值。 在System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader阅读器中,Int32序号)在System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandlingTProperty in lambda_method(闭包,Shaper )中在System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnlyTEntity in lambda_method(闭包,(在System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper中)在System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()中,在System.Linq.Enumerable.FirstOrDefaultTSource中,在System.Linq.Queryable.FirstOrDefaultTSource中
数据库结构中的代码没有任何修改。异常在几个地方抛出。其他应用程序(不是windows服务)在同一个数据库中正常运行。由于我可以检查一些查询是否运行正常,只有少数查询抛出此异常。类型是多种多样的。有时它不能从字符串转换为int32,有时(在其他查询中)它不能从int32转换为字符串。
要解决这个问题,我们必须重新启动Windows服务。
我对记忆没有任何问题(我的第一个嫌疑人)。服务使用大约100-150 of的内存。
环境:Framework4.0,EF 6.1.3,64位,SQL Server 2012 Express。
发布于 2020-03-23 22:53:55
这里似乎需要做大量的日志工作。我建议的是,首先,在代码抛出异常的每个地方调试这些案例并编写日志。
为了预防起见,请尽量检查对象中的属性是否是可转换的--使用int.TryParse
:
if(int.TryParse(X, out intVar)
{
}
else
{
//failed to convert
}
还可以尝试捕捉并发出带有确切堆栈跟踪的日志错误,对于字符串异常来说,这更好,因为您不能尝试对string属性进行解析。
这里没有简单的方法,你必须把这个一片片地挖出来。
https://stackoverflow.com/questions/41839754
复制相似问题