babalae/better-genshin-impact · error · ArgumentException
参数ItemName和ItemNames不能同时为空
Error message
参数ItemName和ItemNames不能同时为空
What it means
Thrown as ArgumentException by CountInventoryItemParam.Validate when both ItemName and ItemNames are empty/whitespace. The task needs at least one item name to count; providing none means there is nothing to do and indicates a caller error.
Source
Thrown at BetterGenshinImpact/GameTask/Common/Job/CountInventoryItemParam.cs:50
public void Validate()
{
ItemNames ??= [];
bool hasItemName = !string.IsNullOrWhiteSpace(ItemName);
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
- Set at least one of ItemName or ItemNames before calling Validate().
- Add an earlier guard in the calling code to reject empty user input before constructing the param.
- If counting is optional, skip the task entirely rather than validating an empty param.
Example fix
// before
var param = new CountInventoryItemParam { GridScreenName = ... };
param.Validate(); // throws — no item specified
// after
var param = new CountInventoryItemParam { GridScreenName = ..., ItemName = "摩拉" };
param.Validate(); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(param.ItemName) && param.ItemNames.Count == 0)
{
// no items specified — abort or prompt user
} Type guard
static bool HasAtLeastOneItem(CountInventoryItemParam p)
=> !string.IsNullOrWhiteSpace(p.ItemName) || p.ItemNames.Count > 0; Try / catch
try { param.Validate(); }
catch (ArgumentException ex) when (ex.Message.Contains("不能同时为空")) { /* prompt for item name */ } Prevention
- Require item specification in the UI/config layer before building the param.
- Use a constructor that mandates at least one item name.
When it happens
Trigger: Constructing a CountInventoryItemParam without setting ItemName or ItemNames (both left at defaults: null and empty list), then calling Validate().
Common situations: A script creates the param object but forgets to populate the item name(s). The item name was read from user input that turned out to be empty. A deserialized config object had both fields blank.
Related errors
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/c6c9cb4577b58d1c.
Report an issue: GitHub.