babalae/better-genshin-impact · error · ArgumentException
参数ItemNames不能包含空名称
Error message
参数ItemNames不能包含空名称
What it means
Thrown as ArgumentException by CountInventoryItemParam.Validate when the ItemNames list contains one or more entries that are null, empty, or whitespace-only. Even a single blank entry would cause downstream item matching to silently fail or match nothing, so the validator rejects the whole list upfront.
Source
Thrown at BetterGenshinImpact/GameTask/Common/Job/CountInventoryItemParam.cs:55
bool hasItemNames = ItemNames.Count > 0;
if (!hasItemName)
{
ItemName = null;
}
if (hasItemName && hasItemNames)
{
throw new ArgumentException($"参数{nameof(ItemName)}和{nameof(ItemNames)}不能同时使用");
}
if (!hasItemName && !hasItemNames)
{
throw new ArgumentException($"参数{nameof(ItemName)}和{nameof(ItemNames)}不能同时为空");
}
if (ItemNames.Any(string.IsNullOrWhiteSpace))
{
throw new ArgumentException($"参数{nameof(ItemNames)}不能包含空名称");
}
}
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Filter out blank entries before assigning: param.ItemNames = names.Where(n => !string.IsNullOrWhiteSpace(n)).ToList().
- Validate source input (e.g., split result) and remove empty tokens immediately after splitting.
- Add per-entry validation in the UI/script layer before constructing the param.
Example fix
// before
param.ItemNames = rawNames.Split(',').ToList(); // may contain ""
param.Validate(); // throws
// after
param.ItemNames = rawNames.Split(',')
.Select(n => n.Trim())
.Where(n => !string.IsNullOrWhiteSpace(n))
.ToList();
param.Validate(); Defensive patterns
Strategy: validation
Validate before calling
param.ItemNames = param.ItemNames
.Where(n => !string.IsNullOrWhiteSpace(n))
.Select(n => n.Trim())
.ToList(); Type guard
static bool ItemNamesAreClean(List<string> names)
=> names.All(n => !string.IsNullOrWhiteSpace(n)); Try / catch
try { param.Validate(); }
catch (ArgumentException ex) when (ex.Message.Contains("不能包含空名称")) { /* filter blanks, retry */ } Prevention
- Always filter and trim list entries at construction time.
- When splitting user input, immediately remove empty tokens.
When it happens
Trigger: Setting ItemNames to a list like ["摩拉", "", "原石"] or ["摩拉", null, "原石"] — any whitespace entry triggers it because ItemNames.Any(string.IsNullOrWhiteSpace) returns true.
Common situations: A list was built from user input or split from a comma-separated string without trimming/filtering empties. A deserialization produced null or empty strings. An upstream filtering step was skipped.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/50d3477b31efa9e3.
Report an issue: GitHub.