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
- Open the manifest.json file and verify it contains a valid JSON object with the required Manifest properties.
- If the file contains 'null', replace it with a proper manifest object: { "name": "...", "version": "...", "main": "..." }.
- Check for file encoding issues (BOM, UTF-16) that might confuse the deserializer.
- 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
- Validate manifest.json is a non-null JSON object before deserialization.
- Use a manifest JSON schema validator.
- Check file encoding (UTF-8 without BOM is safest for System.Text.Json).
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
- 无法解析 RecognitionObject 配置文件: {filePath}
- Failed to deserialize macro
- 解析配置组JSON配置失败
- manifest.json: name is required.
- manifest.json: version is required.
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/e0ca963b243ad745.
Report an issue: GitHub.