YamlDotNet
YamlDotNet copied to clipboard
More detailed deserialization error messages?
Is there a way to get more detailed deserialization errors? When there's a problem with the model I'm trying to deserialize into (e.g., I've defined a property as a string when it needs to be a collection of strings), I'm generally reduced to commenting out all but one property in the target model, running the program, see if the exception occurs, rinse & repeat.
Perhaps some form of logging facility? Or is one already built in?
The exception should indicate the line number and line offset of the error, as well as a message explaining the error. What additional information would be helpful to you ?
What would help me is the name of the property being bound to, because so far most of the errors have been associated with defining the target property incorrectly. For example:
public class TestTarget { [YamlMember(Alias = "property1"] public string Property1 {get; set;} }
yaml file:
property1 - some text
This will fail because Property1 should've been declared as a collection of strings, not a single string. But knowing the line and column where the error took place in the code isn't as helpful as knowing which target property failed to initialize.
If the target property name was included in the exception message it would be helpful.
Apologies if this info is already present and I'm just not seeing it.
I see what you mean. I agree that this information would be useful. It shouldn't be too hard to add that information. I'll see what can be done.
@aaubry This issue is important. Please report the actual property name that cannot be deserialized on error. I wasted 30 mins investigating a failed deserialization because the line/char number are inaccurate and do not point to the actual property. Instead they seem to point to the 'parent' line of the failed property (the line beginning/after the -) which in this case was many lines above the actual problem.
All you need to do is report the name of the actual property/properties in the exception message.
Any progress on this? I would really appreciate this info also in a project I am working on. Thank-you