1

Closed

Incorrect error message when parsing integer value

description

Model type
public class MyType
{
    public int Id { get; set; }
}
 
json object: {"Id":fdsf}
 
It says Error parsing "boolean value." instead of "integer value"
 
Full Error text:
 
{"ExceptionType":"Newtonsoft.Json.JsonReaderException","Message":"Error parsing boolean value. Line 1, position 6.","StackTrace":" at Newtonsoft.Json.JsonTextReader.ParseFalse() in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonTextReader.cs:line 1452\r\n at Newtonsoft.Json.JsonTextReader.ParseValue() in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonTextReader.cs:line 935\r\n at Newtonsoft.Json.JsonTextReader.ReadInternal() in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonTextReader.cs:line 458\r\n at Newtonsoft.Json.JsonReader.ReadAsInt32Internal() in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonReader.cs:line 481\r\n at Newtonsoft.Json.JsonTextReader.ReadAsInt32() in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonTextReader.cs:line 414\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter, Boolean inArray) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 1149\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 1227\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateObject(JsonReader reader, JsonObjectContract contract, String id) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 989\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 444\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 245\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 230\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 126\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 483\r\n at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in c:\Dev\Releases\Working\GitHub\Newtonsoft.Json\Src\Newtonsoft.Json\JsonSerializer.cs:line 461\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.<>c__DisplayClass5.<ReadFromStreamAsync>b__4() in C:\WebStackRuntime\aspnetwebstack\src\System.Net.Http.Formatting\Formatting\JsonMediaTypeFormatter.cs:line 244\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken) in C:\WebStackRuntime\aspnetwebstack\src\Common\TaskHelpers.cs:line 176","InnerException":null}
Closed Mar 24, 2012 at 11:44 AM by JamesNK
The reason it says that is because the first character is 'f' and Json.NET attempts to read the value as a boolean (which it would then convert to an int)

comments