I have an application where in the startup, I register NewtonSoft with error logging on serialization. When I check my application log, I can see there are error logs but I am having trouble pin pointing or recreating the error.
The error: Failed during serialization: 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;
};
})
I did a search in my application for serial
- A couple classes have the [Serializable] attribute
I also use DeserializeObject
JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonValue);
I tried and set jsonValue to null but unfortunately that did not trigger SerializerSettings.Error.
Any tips or suggestions on generating a SerializerSettings error or debugging would be greatly appreciated.