babalae/better-genshin-impact · error · NullReferenceException
Config为空
Error message
Config为空
What it means
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.
Source
Thrown at BetterGenshinImpact/Core/Script/Dependence/Dispatcher.cs:281
}
}
}
}
var autoEatConfig = TaskContext.Instance().Config.AutoEatConfig;
return await new AutoEatTask(new AutoEatParam()
{
CheckInterval = autoEatConfig.CheckInterval,
EatInterval = autoEatConfig.EatInterval,
ShowNotification = autoEatConfig.ShowNotification,
FoodName = foodName
}).Start(cancellationToken);
}
case "CountInventoryItem":
{
if (soloTask.Config == null)
{
throw new NullReferenceException($"{nameof(soloTask.Config)}为空");
}
GridScreenName gridScreenName = ScriptObjectConverter.GetValue((ScriptObject)soloTask.Config, "gridScreenName", (GridScreenName?)null) ?? throw new Exception("gridScreenName为空或错误");
string? itemName = ScriptObjectConverter.GetValue((ScriptObject)soloTask.Config, "itemName", (string?)null);
IEnumerable<string>? itemNames = ScriptObjectConverter.GetValue<string>((ScriptObject)soloTask.Config, "itemNames");
CountInventoryItemParam param = new()
{
GridScreenName = gridScreenName,
ItemName = itemName,
ItemNames = itemNames?.ToList() ?? []
};
var result = await new CountInventoryItem(param).Start(cancellationToken);
if (param.ItemName != null)
{
return result;
}
else
{View on GitHub (pinned to a7cb36712d)
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.
Example fix
// before (JS)
dispatcher.RunTask(new SoloTask('CountInventoryItem')); // Config null -> throws
// after (JS)
dispatcher.RunTask(new SoloTask('CountInventoryItem', {
gridScreenName: '5x10',
itemName: 'Mora'
})); Defensive patterns
Strategy: validation
Validate before calling
// JS side
if (!soloTask.Config) throw new Error('CountInventoryItem requires a Config object');
dispatcher.RunTask(soloTask); Type guard
// JS
function soloTaskHasConfig(t) { return t != null && t.Config != null; } Prevention
- 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.
When it happens
Trigger: JS calls `new SoloTask('CountInventoryItem')` (name-only constructor, Config stays null) then RunTask. Or `new SoloTask('CountInventoryItem', null)`.
Common situations: Author used the single-arg SoloTask constructor. Author thought the task had defaults but it requires explicit config.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/cf6b31888608f386.
Report an issue: GitHub.