hanssens / localstorage

LocalStorage for .NET - A simple and lightweight tool for persisting data in dotnet (core) apps.
MIT License
74 stars 17 forks source link

Reopening .localstorage file may lead to JsonReaderException #19

Closed hanssens closed 6 years ago

hanssens commented 7 years ago

Reopening an existing .localstorage file may lead to the following exception:

JsonReaderException : Additional text encountered after finished reading JSON content

Stacktrace:

Newtonsoft.Json.JsonReaderException : Additional text encountered after finished reading JSON content: t. Path '', line 1, position 67.
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
hanssens commented 6 years ago

Still unknown when this occurs, but the cause being that the JSON structure might become corrupted. This is an example output:

{
    "foo":"175690",
    "bar":"\"U20521\"",
    "from":"\"2018-05-30T10:37:45.2329671+02:00\"",
    "until":"\"2018-06-29T10:37:45.3339772+02:00\""
}
}

... which actually should be:

{
    "foo":"175690",
    "bar":"\"U20521\"",
    "from":"\"2018-05-30T10:37:45.2329671+02:00\"",
    "until":"\"2018-06-29T10:37:45.3339772+02:00\""
}

/cc Thanks @bryandh, for reporting this as well.

hanssens commented 6 years ago

May have been fixed in the latest v2.0.0-beta-2 release, which is now published on NuGet.

hanssens commented 6 years ago

Confirmed. This fixes it.