babalae/better-genshin-impact · critical · Exception
Failed to deserialize PathingTask
Error message
Failed to deserialize PathingTask
What it means
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.
Source
Thrown at BetterGenshinImpact/GameTask/AutoPathing/Model/PathingTask.cs:95
var conditionDefinition = ConditionDefinitions.Definitions["采集物"];
var materialList = conditionDefinition.ObjectOptions?.ToList() ?? new List<string>();
//跳过第一个目录,i从1开始,(一级目录必定不是采集物),对比每一个采集物名称
for (var i = 1; i < level; i++)
{
var materialName = fileNames[i];
if (materialList.Contains(materialName))
{
return materialName;
}
}
return null;
}
public static PathingTask? BuildFromFilePath(string filePath)
{
//var json = File.ReadAllText(filePath);
var task = JsonSerializer.Deserialize<PathingTask>(JsonMerger.getMergePathingJson(filePath), PathRecorder.JsonOptions) ?? throw new Exception("Failed to deserialize PathingTask");
task.FileName = Path.GetFileName(filePath);
task.FullPath = filePath;
//添加区分怪物拾取标志
foreach (var taskPosition in task.Positions)
{
taskPosition.PointExtParams.EnableMonsterLootSplit = task.Info.EnableMonsterLootSplit;
}
// 比较版本号大小 BgiVersion
if (!string.IsNullOrWhiteSpace(task.Info.BgiVersion) && Global.IsNewVersion(task.Info.BgiVersion))
{
TaskControl.Logger.LogError("地图追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} , 禁止运行,请更新 BetterGI 版本!", task.FileName, task.Info.BgiVersion, Global.Version);
TaskControl.Logger.LogError("地图追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} , 禁止运行,请更新 BetterGI 版本!", task.FileName, task.Info.BgiVersion, Global.Version);
TaskControl.Logger.LogError("地图追踪任务 {Name} 版本号要求 {BgiVersion} 大于当前 BetterGI 版本号 {CurrentVersion} , 禁止运行,请更新 BetterGI 版本!", task.FileName, task.Info.BgiVersion, Global.Version);
return null;
}
return task;
}
View on GitHub (pinned to a7cb36712d)
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.
Example fix
// before
var task = JsonSerializer.Deserialize<PathingTask>(JsonMerger.getMergePathingJson(filePath), PathRecorder.JsonOptions)
?? throw new Exception("Failed to deserialize PathingTask");
// after
var merged = JsonMerger.getMergePathingJson(filePath);
if (string.IsNullOrWhiteSpace(merged) || merged.Trim() == "null")
{
throw new InvalidOperationException($"PathingTask 文件合并后内容无效: {filePath}");
}
var task = JsonSerializer.Deserialize<PathingTask>(merged, PathRecorder.JsonOptions)
?? throw new InvalidOperationException($"PathingTask 反序列化结果为 null: {filePath}"); Defensive patterns
Strategy: validation
Validate before calling
var merged = JsonMerger.getMergePathingJson(filePath);
if (string.IsNullOrWhiteSpace(merged) || merged.Trim() == "null")
{
throw new InvalidOperationException($"PathingTask 文件合并后内容无效: {filePath}");
}
var preview = JsonSerializer.Deserialize<PathingTask>(merged, PathRecorder.JsonOptions);
if (preview is null) throw new InvalidOperationException($"PathingTask 反序列化预检为 null: {filePath}"); Type guard
bool IsValidPathingFile(string filePath)
{
try
{
var t = PathingTask.BuildFromFilePath(filePath);
return t is not null;
}
catch { return false; }
} Prevention
- 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.
When it happens
Trigger: BuildFromFilePath(filePath): JsonMerger.getMergePathingJson(filePath) returns content that deserializes to null (literal null, empty, or a merge that produced null).
Common situations: 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.
Related errors
- 无法解析 RecognitionObject 配置文件: {filePath}
- Failed to deserialize macro
- 解析配置组JSON配置失败
- Failed to deserialize JSON.
- 路径文件解析失败:{fileName}
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/dccc0e4a0ea1319e.
Report an issue: GitHub.