1

Closed

NullReferenceException when deserializing empty string

description

The following code:
 
new JsonSerializer().Deserialize(new JsonTextReader(new StringReader("''")));
 
produces the following exception in multiple versions of Json.NET including 4.5 release 4:
 
System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=Newtonsoft.Json
  StackTrace:
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, Object existingValue)
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract, JsonConverter converter, JsonContainerContract containerContract)
       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, Type objectType)
       at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader)
       at ConsoleApplication1.Program.Main()
Closed May 4, 2012 at 12:06 PM by JamesNK
Fixed.

comments