我的应用程序在启动时,我会注册NewtonSoft并开启错误记录序列化。当我检查我的应用程序日志时,我可以看到有错误日志,但我很难定位或重现错误。
错误信息: 序列化期间失败:MoveNextAction.Method.ReturnTypeCustomAttributes
Startup.cs
.AddControllersAsServices().AddNewtonsoftJson(options =>
{
options.UseMemberCasing();
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.AllowInputFormatterExceptionMessages = true;
options.SerializerSettings.Formatting = Formatting.None;
options.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = null
};
options.SerializerSettings.Error = (sender, args) =>
{
_logger.LogError($"Failed during serialization: {args.ErrorContext.Path}", args.ErrorContext.Error);
args.ErrorContext.Handled = true;
};
})
我在我的应用程序中搜索了串行
- 有几个类具有[Serializable]属性
我还使用DeserializeObject
JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonValue);
我尝试将jsonValue设置为null,但不幸的是这并没有触发SerializerSettings.Error。
如果您有任何提示或建议来生成SerializerSettings错误或进行调试,将不胜感激。
args.ErrorContext.Error
应该向你展示正在被序列化并失败的类型(在堆栈跟踪的底部)。 - OfirDargs.ErrorContext.Path
的值。但args.ErrorContext.Error
的值是多少呢? - OfirD