Closed smhmhmd closed 1 year ago
The NRE is definitely not very helpful, and i agree that a more meaningful exception should be thrown.
But it's not an edge case related to JProperty.Load as you seem to suspect. It's rather because you use the JsonValidatingReader (which is obsolete, btw) without a schema -- that cannot work. And a meaningful exception other than this unhelpful NRE should hint at that fact.
Basically, the issue can be demonstrated without involving JProperty.Load:
Newtonsoft.Json.Linq.JToken jtoken = Newtonsoft.Json.Linq.JToken.Parse(@"{ ""foo"": ""bar"" }");
Newtonsoft.Json.JsonReader jsonRdr = jtoken.CreateReader();
Newtonsoft.Json.JsonValidatingReader validatingRdr = new Newtonsoft.Json.JsonValidatingReader(jsonRdr);
validatingRdr.Read();
(Dotnetfiddle: https://dotnetfiddle.net/5hXYOi)
...and there you got exactly the same NRE. It's all about reading from a JsonValidatingReader that is lacking a schema to validate against.
(If you would be so kind, it would be nice if you could edit the title of your issue report so as not to put emphasis on JProperty.Load that is distracting from the actual issue.)
a meaningful exception other than this unhelpful NRE should hint at that fact.
If it is possible to add a meaningful exception that would be great, I found one more example where a meaningful exception would be helpful.
(If you would be so kind, it would be nice if you could edit the title of your issue report so as not to put emphasis on JProperty.Load that is distracting from the actual issue.)
I hope the new title is good with you.
I hope the new title is good with you.
Thanks! Now keep our fingers crossed that the author and maintainer of Newtonsoft.Json sees and acts upon this issue report...
JsonValidatingReader is obsolete.
Source JSON
Note: This is an edge case.
Expected behavior
Expected exception for bad input such as
Error reading JProperty from JsonReader.
fromNewtonsoft.Json.Linq.JProperty.Load()
Actual behavior
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Steps to reproduce