1

Closed

Json.Net throws exception when deserializing anything longer than Int64

description

JsonSerializer ser = new JsonSerializer();
JsonTextReader reader = new JsonTextReader(new StringReader("18024864231475722138"));
Console.WriteLine("Val - " + ser.Deserialize(reader).ToString());
 
Exception -
 
---- System.OverflowException : Value was either too large or too small for an Int64.
 
at Newtonsoft.Json.JsonTextReader.ParseNumber()
 
at Newtonsoft.Json.JsonTextReader.ParseValue()
 
at Newtonsoft.Json.JsonTextReader.ReadInternal()
 
at Newtonsoft.Json.JsonTextReader.Read()
 
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter, Boolean inArray)
 
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType)
 
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
 
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader)
 
----- Inner Stack Trace -----
 
at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
 
at Newtonsoft.Json.JsonTextReader.ParseNumber()
Closed Mar 31, 2012 at 9:14 AM by JamesNK
long is the max value for integers. Deserialize to a decimal or double.

comments