{"record":{"id":"dccc0e4a0ea1319e","repo":"babalae/better-genshin-impact","slug":"failed-to-deserialize-pathingtask","errorCode":null,"errorMessage":"Failed to deserialize PathingTask","messagePattern":"Failed to deserialize PathingTask","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"BetterGenshinImpact/GameTask/AutoPathing/Model/PathingTask.cs","lineNumber":95,"sourceCode":"        var conditionDefinition = ConditionDefinitions.Definitions[\"采集物\"];\n        var materialList = conditionDefinition.ObjectOptions?.ToList() ?? new List<string>();\n        \n        //跳过第一个目录，i从1开始,（一级目录必定不是采集物），对比每一个采集物名称 \n        for (var i = 1; i < level; i++)\n        {\n            var materialName = fileNames[i];\n            if (materialList.Contains(materialName))\n            {\n                return materialName;\n            }\n        }\n        return null;\n    }\n\n    public static PathingTask? BuildFromFilePath(string filePath)\n    {\n        //var json = File.ReadAllText(filePath);\n        var task = JsonSerializer.Deserialize<PathingTask>(JsonMerger.getMergePathingJson(filePath), PathRecorder.JsonOptions) ?? throw new Exception(\"Failed to deserialize PathingTask\");\n        task.FileName = Path.GetFileName(filePath);\n        task.FullPath = filePath;\n        //添加区分怪物拾取标志\n        foreach (var taskPosition in task.Positions)\n        {\n            taskPosition.PointExtParams.EnableMonsterLootSplit = task.Info.EnableMonsterLootSplit;\n        }\n        // 比较版本号大小 BgiVersion\n        if (!string.IsNullOrWhiteSpace(task.Info.BgiVersion) && Global.IsNewVersion(task.Info.BgiVersion))\n        {\n            TaskControl.Logger.LogError(\"地图追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} ， 禁止运行，请更新 BetterGI 版本！\", task.FileName, task.Info.BgiVersion, Global.Version);\n            TaskControl.Logger.LogError(\"地图追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} ， 禁止运行，请更新 BetterGI 版本！\", task.FileName, task.Info.BgiVersion, Global.Version);\n            TaskControl.Logger.LogError(\"地图追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} ， 禁止运行，请更新 BetterGI 版本！\", task.FileName, task.Info.BgiVersion, Global.Version);\n            return null;\n        }\n        return task;\n    }\n","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/AutoPathing/Model/PathingTask.cs#L77-L113","documentation":"Thrown by PathingTask.BuildFromFilePath when JsonSerializer.Deserialize<PathingTask> over the merged JSON (JsonMerger.getMergePathingJson) yields null. This means the pathing-task file (after include-merging) deserialized to no object, so the task is unusable.","triggerScenarios":"BuildFromFilePath(filePath): JsonMerger.getMergePathingJson(filePath) returns content that deserializes to null (literal null, empty, or a merge that produced null).","commonSituations":"The pathing JSON is empty/corrupt; a referenced include ($include) resolved to null or missing; schema mismatch where the root isn't a PathingTask object; file truncated.","solutions":["Open the pathing JSON and validate it is a non-null object with Info and Positions.","Check any include/merge directives resolve to existing, valid fragments.","Re-download or recreate the pathing-task file from a known-good source.","Validate the JSON against the PathingTask schema before running."],"exampleFix":"// before\nvar task = JsonSerializer.Deserialize<PathingTask>(JsonMerger.getMergePathingJson(filePath), PathRecorder.JsonOptions)\n           ?? throw new Exception(\"Failed to deserialize PathingTask\");\n\n// after\nvar merged = JsonMerger.getMergePathingJson(filePath);\nif (string.IsNullOrWhiteSpace(merged) || merged.Trim() == \"null\")\n{\n    throw new InvalidOperationException($\"PathingTask 文件合并后内容无效: {filePath}\");\n}\nvar task = JsonSerializer.Deserialize<PathingTask>(merged, PathRecorder.JsonOptions)\n           ?? throw new InvalidOperationException($\"PathingTask 反序列化结果为 null: {filePath}\");","handlingStrategy":"validation","validationCode":"var merged = JsonMerger.getMergePathingJson(filePath);\nif (string.IsNullOrWhiteSpace(merged) || merged.Trim() == \"null\")\n{\n    throw new InvalidOperationException($\"PathingTask 文件合并后内容无效: {filePath}\");\n}\nvar preview = JsonSerializer.Deserialize<PathingTask>(merged, PathRecorder.JsonOptions);\nif (preview is null) throw new InvalidOperationException($\"PathingTask 反序列化预检为 null: {filePath}\");","typeGuard":"bool IsValidPathingFile(string filePath)\n{\n    try\n    {\n        var t = PathingTask.BuildFromFilePath(filePath);\n        return t is not null;\n    }\n    catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Validate pathing-task JSON (and its includes) at import time.","Run a JSON-schema check before allowing a task into the library.","Watch include/merge resolution — a bad include can null the merge."],"tags":["json","deserialization","pathing","file"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}