Devolutions/UniGetUI · error · InvalidDataException

JsonNode? inc_pkg was null, when it shouldn't

Error message

JsonNode? inc_pkg was null, when it shouldn't

What it means

Same loop as error 102 but for the 'incompatible_packages' array. SerializableBundle.LoadFromJson iterates JsonNode? elements from data["incompatible_packages"]?.AsArray2(); any JSON `null` literal element makes the throw fire with message 'JsonNode? inc_pkg was null, when it shouldn't'. The exception propagates uncaught out of LoadFromJson, aborting the bundle load.

Source

Thrown at src/UniGetUI.PackageEngine.Serializable/SerializableBundle.cs:59

        public override void LoadFromJson(JsonNode data)
        {
            this.export_version = data[nameof(export_version)]?.GetVal<double>() ?? 0;
            this.incompatible_packages_info =
                data[nameof(incompatible_packages_info)]?.GetVal<string>() ?? IncompatMessage;
            this.packages = new List<SerializablePackage>();
            this.incompatible_packages = new List<SerializableIncompatiblePackage>();

            foreach (JsonNode? pkg in data[nameof(packages)]?.AsArray2() ?? new())
            {
                if (pkg is null)
                    throw new InvalidDataException("JsonNode? pkg was null, when it shouldn't");
                packages.Add(new SerializablePackage(pkg));
            }

            foreach (JsonNode? inc_pkg in data[nameof(incompatible_packages)]?.AsArray2() ?? new())
            {
                if (inc_pkg is null)
                    throw new InvalidDataException("JsonNode? inc_pkg was null, when it shouldn't");
                incompatible_packages.Add(new SerializableIncompatiblePackage(inc_pkg));
            }
        }

        public override JsonObject AsJsonNode()
        {
            JsonObject obj = new();
            obj.Add(nameof(export_version), export_version);
            obj.Add(
                nameof(packages),
                new JsonArray(packages.Select(p => p.AsJsonNode()).ToArray())
            );
            obj.Add(nameof(incompatible_packages_info), incompatible_packages_info);
            obj.Add(
                nameof(incompatible_packages),
                new JsonArray(incompatible_packages.Select(p => p.AsJsonNode()).ToArray())
            );
            return obj;

View on GitHub (pinned to 9b1d7d0eab)

Solutions

  1. Regenerate the bundle export so incompatible-packages entries are well-formed.
  2. Pre-clean the 'incompatible_packages' array to strip null elements before import.
  3. Confirm export_version == 3 (SerializableBundle.ExpectedVersion) to rule out a format mismatch.
  4. Relax the guard to `if (inc_pkg is null) continue;` if null slots should be tolerated rather than aborting the whole import.
  5. Open the JSON and inspect the incompatible_packages array indices that are null.

Example fix

// before (SerializableBundle.cs:56-61)
foreach (JsonNode? inc_pkg in data[nameof(incompatible_packages)]?.AsArray2() ?? new())
{
    if (inc_pkg is null)
        throw new InvalidDataException("JsonNode? inc_pkg was null, when it shouldn't");
    incompatible_packages.Add(new SerializableIncompatiblePackage(inc_pkg));
}

// after — tolerate corrupt null slots
foreach (JsonNode? inc_pkg in data[nameof(incompatible_packages)]?.AsArray2() ?? new())
{
    if (inc_pkg is null) continue;
    incompatible_packages.Add(new SerializableIncompatiblePackage(inc_pkg));
}
Defensive patterns

Strategy: validation

Validate before calling

// Strip null elements from the 'incompatible_packages' array before deserializing.
static JsonNode SanitizeBundle(JsonNode node)
{
    if (node is JsonObject obj && obj["incompatible_packages"] is JsonArray inc)
    {
        JsonArray clean = new();
        foreach (var p in inc.Where(n => n is not null))
            clean.Add(p.DeepClone());
        obj["incompatible_packages"] = clean;
    }
    return node;
}

var safe = SanitizeBundle(JsonNode.Parse(File.ReadAllText(path))!);
var bundle = new SerializableBundle(safe);

Type guard

static bool BundleIncompatHaveNoNulls(JsonNode node)
{
    if (node is not JsonObject obj) return false;
    if (obj["incompatible_packages"] is not JsonArray arr) return true;
    return arr.All(e => e is not null);
}

Try / catch

try
{
    var bundle = new SerializableBundle(JsonNode.Parse(json)!);
}
catch (InvalidDataException ex) when (ex.Message.Contains("inc_pkg was null"))
{
    Logger.Error("Bundle file has null incompatible-package entries; refusing to import corrupt file.");
}

Prevention

When it happens

Trigger: Calling LoadFromJson(node) / `new SerializableBundle(node)` where node["incompatible_packages"] is a JSON array containing one or more null elements. Note the array may be entirely absent (then `?? new()` yields an empty array and no throw), so the failure specifically requires a present array with null members.

Common situations: Bundle exports containing 'incompatible packages' (packages from a local source or an unavailable manager) where the exporter wrote a null placeholder; truncated or hand-edited export files; imports across UniGetUI versions with differing incompatible-package schemas.

Related errors


AI-assisted analysis of Devolutions/UniGetUI@9b1d7d0eab (2026-08-13). Data as JSON: /api/errors/9ebd116b6c7738f1. Report an issue: GitHub.