{"record":{"id":"cf6b31888608f386","repo":"babalae/better-genshin-impact","slug":"config","errorCode":null,"errorMessage":"Config为空","messagePattern":"Config为空","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs","lineNumber":281,"sourceCode":"                                }\n                            }\n                        }\n                    }\n\n                    var autoEatConfig = TaskContext.Instance().Config.AutoEatConfig;\n                    return await new AutoEatTask(new AutoEatParam()\n                    {\n                        CheckInterval = autoEatConfig.CheckInterval,\n                        EatInterval = autoEatConfig.EatInterval,\n                        ShowNotification = autoEatConfig.ShowNotification,\n                        FoodName = foodName\n                    }).Start(cancellationToken);\n                }\n            case \"CountInventoryItem\":\n                {\n                    if (soloTask.Config == null)\n                    {\n                        throw new NullReferenceException($\"{nameof(soloTask.Config)}为空\");\n                    }\n                    GridScreenName gridScreenName = ScriptObjectConverter.GetValue((ScriptObject)soloTask.Config, \"gridScreenName\", (GridScreenName?)null) ?? throw new Exception(\"gridScreenName为空或错误\");\n                    string? itemName = ScriptObjectConverter.GetValue((ScriptObject)soloTask.Config, \"itemName\", (string?)null);\n                    IEnumerable<string>? itemNames = ScriptObjectConverter.GetValue<string>((ScriptObject)soloTask.Config, \"itemNames\");\n                    CountInventoryItemParam param = new()\n                    {\n                        GridScreenName = gridScreenName,\n                        ItemName = itemName,\n                        ItemNames = itemNames?.ToList() ?? []\n                    };\n\n                    var result = await new CountInventoryItem(param).Start(cancellationToken);\n                    if (param.ItemName != null)\n                    {\n                        return result;\n                    }\n                    else\n                    {","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs#L263-L299","documentation":"NullReferenceException thrown at line 281 in the CountInventoryItem case when soloTask.Config is null. CountInventoryItem needs at least a gridScreenName and an item name/list, all of which live in Config, so a null Config makes the task impossible. Note the slightly misleading exception type (NullReferenceException with a Chinese message) — it is a deliberate guard, not an accidental dereference.","triggerScenarios":"JS calls `new SoloTask('CountInventoryItem')` (name-only constructor, Config stays null) then RunTask. Or `new SoloTask('CountInventoryItem', null)`.","commonSituations":"Author used the single-arg SoloTask constructor. Author thought the task had defaults but it requires explicit config.","solutions":["Pass a config object: `new SoloTask('CountInventoryItem', { gridScreenName: '...', itemName: '...' })`.","Always use the (name, config) constructor for tasks that require configuration.","Validate that Config is non-null in JS before calling RunTask for CountInventoryItem."],"exampleFix":"// before (JS)\ndispatcher.RunTask(new SoloTask('CountInventoryItem')); // Config null -> throws\n\n// after (JS)\ndispatcher.RunTask(new SoloTask('CountInventoryItem', {\n  gridScreenName: '5x10',\n  itemName: 'Mora'\n}));","handlingStrategy":"validation","validationCode":"// JS side\nif (!soloTask.Config) throw new Error('CountInventoryItem requires a Config object');\ndispatcher.RunTask(soloTask);","typeGuard":"// JS\nfunction soloTaskHasConfig(t) { return t != null && t.Config != null; }","tryCatchPattern":null,"preventionTips":["Always use the SoloTask(name, config) constructor for CountInventoryItem.","Never use the name-only constructor for tasks that require config.","Validate Config is non-null before RunTask for config-required tasks."],"tags":["script","count-inventory","config","argument-null"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}