rocksdanister/lively · error · ArgumentNullException
json null/corrupt
Error message
json null/corrupt
What it means
Thrown by the generic JsonStorage<T>.LoadData when Newtonsoft.Json deserialises the file to null. This loader backs most on-disk config/metadata in Lively, so the message is generic. Note the exception TYPE is ArgumentNullException with a message string as paramName — the type does not match the failure (corruption, not a null argument).
Source
Thrown at src/Lively/Lively.Common/Helpers/Storage/JsonStorage.cs:20
using System.IO;
using Newtonsoft.Json;
namespace Lively.Common.Helpers.Storage
{
public static class JsonStorage<T>
{
public static T LoadData(string filePath)
{
// deserialize JSON directly from a file
using StreamReader file = File.OpenText(filePath);
var serializer = new JsonSerializer
{
//TypeNameHandling = TypeNameHandling.Auto
};
var tmp = (T)serializer.Deserialize(file, typeof(T));
//if file is corrupted, json can return null.
return (tmp != null ? tmp : throw new ArgumentNullException("json null/corrupt"));
}
public static void StoreData(string filePath, T data)
{
JsonSerializer serializer = new JsonSerializer
{
Formatting = Formatting.Indented,
//serializer.Converters.Add(new JavaScriptDateTimeConverter());
NullValueHandling = NullValueHandling.Include,
//TypeNameHandling = TypeNameHandling.Auto,
};
using StreamWriter sw = new StreamWriter(filePath);
using JsonWriter writer = new JsonTextWriter(sw);
serializer.Serialize(writer, data, typeof(T));
}
}
}View on GitHub (pinned to c1036feb66)
Solutions
- Open the file and confirm it is non-empty, valid JSON matching T's schema.
- Delete or back up the offending file so the app regenerates defaults on next start.
- Wrap LoadData in try/catch and fall back to default(T) / a fresh settings instance, logging the corruption.
- If maintaining the lib, replace the throw with a typed JsonException/InvalidDataException and pass the file path for diagnostics.
Example fix
// before
return (tmp != null ? tmp : throw new ArgumentNullException("json null/corrupt"));
// after
return tmp ?? throw new JsonException($"{filePath} deserialised to null (empty or wrong schema for {typeof(T).Name})"); Defensive patterns
Strategy: try-catch
Validate before calling
if (!File.Exists(filePath) || new FileInfo(filePath).Length == 0)
return default(T); // or regenerate defaults
var json = File.ReadAllText(filePath);
if (string.IsNullOrWhiteSpace(json) || json.Trim() == "null") return default(T); Type guard
static bool TryLoad<T>(string path, out T value)
{
value = default;
try { value = JsonStorage<T>.LoadData(path); return value != null; }
catch { return false; }
} Try / catch
T cfg;
try { cfg = JsonStorage<T>.LoadData(path); }
catch (ArgumentNullException ex) when (ex.ParamName?.Contains("json null") == true)
{ cfg = DefaultT(); /* reset to defaults and persist */ } Prevention
- Write settings atomically (temp file + rename) to avoid empty/corrupt files.
- Back up config before schema migrations.
- Treat load failure as 'reset to defaults' rather than crash for non-critical state.
When it happens
Trigger: Any JsonStorage<T>.LoadData(filePath) where the file is empty, contains JSON that deserialises to null (e.g. literal "null", or an empty object for a non-nullable reference type that the converter leaves null), or the type T cannot be bound from the content.
Common situations: Empty settings file left by a failed write or reset; hand-edited config that became invalid; upgrade/downgrade where T's shape changed; files with content "null" from a previous bug; encoding/BOM issues.
Related errors
- Corrupted wallpaper metadata
- libmpv depreciated player selected.
- libmpvExt depreciated player selected.
- libvlc depreciated player selected.
- xaml island gif player not available.
AI-assisted analysis of rocksdanister/lively@c1036feb66 (2026-08-13).
Data as JSON: /api/errors/a2e8e2526bf04d51.
Report an issue: GitHub.