{"record":{"id":"e0ca963b243ad745","repo":"babalae/better-genshin-impact","slug":"failed-to-deserialize-json","errorCode":null,"errorMessage":"Failed to deserialize JSON.","messagePattern":"Failed to deserialize JSON\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Project/Manifest.cs","lineNumber":33,"sourceCode":"[Serializable]\npublic class Manifest\n{\n    public int ManifestVersion { get; set; } = 1;\n    public string Name { get; set; } = string.Empty;\n    public string Version { get; set; } = string.Empty;\n    public string? BgiVersion { get; set; }\n    public string Description { get; set; } = string.Empty;\n    public List<Author> Authors { get; set; } = [];\n    public string Main { get; set; } = string.Empty;\n    public string SettingsUi { get; set; } = string.Empty;\n    public string[] Scripts { get; set; } = [];\n    public string[] Library { get; set; } = [];\n    public string[] SavedFiles { get; set; } = [];\n    public string[] HttpAllowedUrls { get; set; } = [];\n\n    public static Manifest FromJson(string json)\n    {\n        var manifest = JsonSerializer.Deserialize<Manifest>(json, Global.ManifestJsonOptions) ?? throw new Exception(\"Failed to deserialize JSON.\");\n        return manifest;\n    }\n\n    public void Validate(string path)\n    {\n        if (string.IsNullOrWhiteSpace(Name))\n        {\n            throw new Exception(\"manifest.json: name is required.\");\n        }\n\n        if (string.IsNullOrWhiteSpace(Version))\n        {\n            throw new Exception(\"manifest.json: version is required.\");\n        }\n\n        if (string.IsNullOrWhiteSpace(Main))\n        {\n            throw new Exception(\"manifest.json: main script is required.\");","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Project/Manifest.cs#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// manifest.json before\nnull\n// after\n{\n  \"name\": \"my-script\",\n  \"version\": \"1.0.0\",\n  \"main\": \"main.js\"\n}","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(json) || json.Trim() == \"null\")\n    throw new InvalidOperationException(\"manifest.json content is null or empty\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var manifest = Manifest.FromJson(json);\n}\ncatch (Exception ex) when (ex.Message == \"Failed to deserialize JSON.\")\n{\n    throw new InvalidOperationException(\"manifest.json deserialized to null — check file content\", ex);\n}\ncatch (System.Text.Json.JsonException ex)\n{\n    throw new InvalidOperationException($\"manifest.json is malformed: {ex.Message}\", ex);\n}","preventionTips":["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)."],"tags":["manifest","json","deserialization","script-project"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}