babalae/better-genshin-impact · error · ArgumentException
角色名集合不能为空。
Error message
角色名集合不能为空。
What it means
Thrown by ParseCharacterNames when the collection is enumerable and all elements are valid strings, but the resulting list is empty (names.Count == 0). An empty collection is not a valid input since there are no characters to process.
Source
Thrown at BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs:143
if (characterNames is not IEnumerable enumerable)
{
throw new ArgumentException("角色名参数必须是字符串集合或 JS Array。", nameof(characterNames));
}
List<string> names = [];
foreach (var item in enumerable)
{
if (item is not string name)
{
throw new ArgumentException("角色名集合中的每个元素都必须是字符串。", nameof(characterNames));
}
names.Add(NormalizeCharacterName(name));
}
if (names.Count == 0)
{
throw new ArgumentException("角色名集合不能为空。", nameof(characterNames));
}
return names;
}
private static string NormalizeCharacterName(string characterName)
{
var name = characterName?.Trim() ?? string.Empty;
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException("角色名不能为空。", nameof(characterName));
}
return name;
}
internal static CharacterDevelopmentCategory ParseCategories(string? categories)
{View on GitHub (pinned to a7cb36712d)
Solutions
- Pass at least one valid character name in the collection.
- Check the array length before calling GetMultiCharacters.
- If no characters are needed, don't call the method at all.
Example fix
// before (wrong) await dev.GetMultiCharacters([]); // after await dev.GetMultiCharacters(['钟离']);
Defensive patterns
Strategy: validation
Validate before calling
// Check collection is non-empty before calling
if (names is ICollection col && col.Count == 0)
{
throw new ArgumentException("characterNames collection must not be empty.");
} Type guard
static bool IsNonEmptyStringCollection(object obj)
{
if (obj is string || obj is not IEnumerable e) return false;
return e.Cast<object>().Any(x => x is string);
} Try / catch
try
{
await dev.GetMultiCharacters(names);
}
catch (ArgumentException ex) when (ex.Message.Contains("不能为空"))
{
// Add at least one character name
} Prevention
- Check the collection has at least one element before calling.
- Don't call GetMultiCharacters if no characters are needed.
- Validate array length from JavaScript callers.
When it happens
Trigger: Called from ParseCharacterNames. The enumerable yields no elements (e.g. empty array, empty list). All type checks pass but names.Count == 0 at the end.
Common situations: JavaScript caller passes an empty array []; C# caller passes an empty List<string>(); the collection was constructed dynamically and ended up empty.
Related errors
- {paramName} 不能为空
- 多角色接口需要字符串集合或 JS Array,单个字符串请使用 GetCharacter。
- 角色名参数必须是字符串集合或 JS Array。
- 角色名集合中的每个元素都必须是字符串。
- 角色名不能为空。
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/cc805805f37ab3e1.
Report an issue: GitHub.