1

Closed

Line Number and Line Position

description

When it is a syntax error, we get line number and line position in error message:
 
     After parsing a value an unexpected character was encountered: :. Line 4, position 21.
 
However, when it is a type error, we do not get line number and line position:
 
     Invalid type. Expected String but got Integer.
 
Can we always get line number and line position? How?
 
Thanks for your time.
Closed Apr 30, 2012 at 1:00 AM by JamesNK
The validation event args has that information on it.

comments

JamesNK wrote Apr 23, 2012 at 4:20 AM

Hi. Please include the complete stacktrace so I have an idea of where the error is being thrown from.

JsonSpc wrote Apr 25, 2012 at 10:18 PM

Newtonsoft.Json.dll!Newtonsoft.Json.JsonValidatingReader.OnValidationEvent(Newtonsoft.Json.Schema.JsonSchemaException exception = {"Invalid type. Expected String but got Integer."}) Line 267 + 0x2a bytes C#
Newtonsoft.Json.dll!Newtonsoft.Json.JsonValidatingReader.RaiseError(string message = "Invalid type. Expected String but got Integer.", Newtonsoft.Json.Schema.JsonSchemaModel schema = {Newtonsoft.Json.Schema.JsonSchemaModel}) Line 261   C#
Newtonsoft.Json.dll!Newtonsoft.Json.JsonValidatingReader.TestType(Newtonsoft.Json.Schema.JsonSchemaModel currentSchema = {Newtonsoft.Json.Schema.JsonSchemaModel}, Newtonsoft.Json.Schema.JsonSchemaType currentType = Integer) Line 775    C#
Newtonsoft.Json.dll!Newtonsoft.Json.JsonValidatingReader.ValidateInteger(Newtonsoft.Json.Schema.JsonSchemaModel schema = {Newtonsoft.Json.Schema.JsonSchemaModel}) Line 636 + 0x13 bytes    C#
Newtonsoft.Json.dll!Newtonsoft.Json.JsonValidatingReader.ValidateCurrentToken() Line 486 + 0x57 bytes   C#
Newtonsoft.Json.dll!Newtonsoft.Json.JsonValidatingReader.Read() Line 449    C#
Newtonsoft.Json.dll!Newtonsoft.Json.Schema.Extensions.Validate(Newtonsoft.Json.Linq.JToken source = {Newtonsoft.Json.Linq.JObject}, Newtonsoft.Json.Schema.JsonSchema schema = {Newtonsoft.Json.Schema.JsonSchema}, Newtonsoft.Json.Schema.ValidationEventHandler validationEventHandler = {Method = {System.Reflection.RuntimeMethodInfo}}) Line 98 + 0xb bytes    C#