I'm facing a strange issue. I haven't had any problems in the past with deserializing huge JSON files but now I have the following code:
private JObject ReadJsonFile(string pathToFile)
{
JObject jsonObject = null;
try
{
using (FileStream s =new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
using (StreamReader sr = new StreamReader(s))
using (JsonReader reader = new JsonTextReader(sr))
{
JsonSerializer serializer = new JsonSerializer();
jsonObject = serializer.Deserialize<JObject>(reader);
}
}
catch (Exception exc)
{
_log.Error($"Error during reading file {exc}");
}
return jsonObject;
}
Which works fine but from time to time during runtime line jsonObject = serializer.Deserialize<JObject>(reader);
throws Out of memory even though the JSON file is around 20 MB which is very strange.
Has anyone had a similar issue ?
The file has a lot of columns; when I open it in Notepad++ it shows 8 099 893 characters in one line. Maybe there is a case for that ?