babalae/better-genshin-impact · error · Exception

Failed to deserialize JSON.

Error message

Failed to deserialize JSON.

What it means

Thrown by Manifest.FromJson when System.Text.Json.JsonSerializer.Deserialize<Manifest> returns null. This indicates the JSON was valid but deserialized to null — typically when the JSON root is literally 'null', or the serializer configuration (Global.ManifestJsonOptions) causes a null result. Note: a malformed JSON throws JsonException, which is a different failure path that propagates without this message.

Source

Thrown at BetterGenshinImpact/Core/Script/Project/Manifest.cs:33

[Serializable]
public class Manifest
{
    public int ManifestVersion { get; set; } = 1;
    public string Name { get; set; } = string.Empty;
    public string Version { get; set; } = string.Empty;
    public string? BgiVersion { get; set; }
    public string Description { get; set; } = string.Empty;
    public List<Author> Authors { get; set; } = [];
    public string Main { get; set; } = string.Empty;
    public string SettingsUi { get; set; } = string.Empty;
    public string[] Scripts { get; set; } = [];
    public string[] Library { get; set; } = [];
    public string[] SavedFiles { get; set; } = [];
    public string[] HttpAllowedUrls { get; set; } = [];

    public static Manifest FromJson(string json)
    {
        var manifest = JsonSerializer.Deserialize<Manifest>(json, Global.ManifestJsonOptions) ?? throw new Exception("Failed to deserialize JSON.");
        return manifest;
    }

    public void Validate(string path)
    {
        if (string.IsNullOrWhiteSpace(Name))
        {
            throw new Exception("manifest.json: name is required.");
        }

        if (string.IsNullOrWhiteSpace(Version))
        {
            throw new Exception("manifest.json: version is required.");
        }

        if (string.IsNullOrWhiteSpace(Main))
        {
            throw new Exception("manifest.json: main script is required.");

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Open the manifest.json file and verify it contains a valid JSON object with the required Manifest properties.
  2. If the file contains 'null', replace it with a proper manifest object: { "name": "...", "version": "...", "main": "..." }.
  3. Check for file encoding issues (BOM, UTF-16) that might confuse the deserializer.
  4. Wrap in try-catch to also handle JsonException from truly malformed JSON.

Example fix

// manifest.json before
null
// after
{
  "name": "my-script",
  "version": "1.0.0",
  "main": "main.js"
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (string.IsNullOrWhiteSpace(json) || json.Trim() == "null")
    throw new InvalidOperationException("manifest.json content is null or empty");

Try / catch

try
{
    var manifest = Manifest.FromJson(json);
}
catch (Exception ex) when (ex.Message == "Failed to deserialize JSON.")
{
    throw new InvalidOperationException("manifest.json deserialized to null — check file content", ex);
}
catch (System.Text.Json.JsonException ex)
{
    throw new InvalidOperationException($"manifest.json is malformed: {ex.Message}", ex);
}

Prevention

When it happens

Trigger: Calling Manifest.FromJson(json) where json is the literal string 'null', or where the JSON structure combined with ManifestJsonOptions causes a null result. The manifest.json file contains 'null' as its entire content.

Common situations: Corrupted manifest.json containing only 'null'. An empty or whitespace file that the serializer interprets as null. A build/packaging process that generated an empty manifest.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/e0ca963b243ad745. Report an issue: GitHub.