{"record":{"id":"c6728bdc2cf74887","repo":"babalae/better-genshin-impact","slug":"js-array","errorCode":null,"errorMessage":"角色名参数必须是字符串集合或 JS Array。","messagePattern":"角色名参数必须是字符串集合或 JS Array。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs","lineNumber":127,"sourceCode":"    public async Task<List<CharacterDevelopmentResult>> GetMultiCharacters(object characterNames, string? categories = null)\n    {\n        var names = ParseCharacterNames(characterNames);\n        var categoryFlags = ParseCategories(categories);\n        return await new CharacterDevelopmentStateMachineTask(names, categoryFlags)\n            .Start(CancellationContext.Instance.Cts.Token);\n    }\n\n    internal static List<string> ParseCharacterNames(object characterNames)\n    {\n        ArgumentNullException.ThrowIfNull(characterNames);\n        if (characterNames is string)\n        {\n            throw new ArgumentException(\"多角色接口需要字符串集合或 JS Array，单个字符串请使用 GetCharacter。\", nameof(characterNames));\n        }\n\n        if (characterNames is not IEnumerable enumerable)\n        {\n            throw new ArgumentException(\"角色名参数必须是字符串集合或 JS Array。\", nameof(characterNames));\n        }\n\n        List<string> names = [];\n        foreach (var item in enumerable)\n        {\n            if (item is not string name)\n            {\n                throw new ArgumentException(\"角色名集合中的每个元素都必须是字符串。\", nameof(characterNames));\n            }\n\n            names.Add(NormalizeCharacterName(name));\n        }\n\n        if (names.Count == 0)\n        {\n            throw new ArgumentException(\"角色名集合不能为空。\", nameof(characterNames));\n        }\n","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/CharacterDevelopment/CharacterDevelopmentTask.cs#L109-L145","documentation":"Thrown by ParseCharacterNames when the characterNames argument is not null, not a string, but also does not implement IEnumerable. The method only accepts string collections (or JS Arrays which implement IList/IEnumerable). Any other type (number, object, boolean) triggers this.","triggerScenarios":"Called from GetMultiCharacters(characterNames, categories) → ParseCharacterNames. characterNames is a non-null, non-string object that is not IEnumerable — e.g. a number, a plain object, or a boolean.","commonSituations":"JavaScript caller passes a non-array object (e.g. {name: '钟离'}) or a primitive; C# caller passes an incompatible type like an int or custom class not implementing IEnumerable.","solutions":["Pass a string array or List<string> from C#, or a JS Array of strings from JavaScript.","Ensure the value is iterable and contains string elements.","Validate the argument type before calling GetMultiCharacters."],"exampleFix":"// before (wrong)\nawait dev.GetMultiCharacters({ name: '钟离' });\n// after\nawait dev.GetMultiCharacters(['钟离']);","handlingStrategy":"validation","validationCode":"// Ensure the argument is an enumerable collection\nif (characterNames is not string && characterNames is not IEnumerable)\n{\n    throw new ArgumentException(\"characterNames must be a string collection or JS Array.\");\n}","typeGuard":"static bool IsValidCharacterNamesArgument(object obj)\n{\n    return obj is null || (obj is not string && obj is IEnumerable);\n}","tryCatchPattern":"try\n{\n    await dev.GetMultiCharacters(names);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"必须是字符串集合\"))\n{\n    // Convert to a proper array/collection\n}","preventionTips":["Always pass a string array or List<string> from C#.","From JavaScript, pass a JS Array, not a plain object or primitive.","Validate the argument is iterable before calling."],"tags":["character-development","argument-validation","type-mismatch","javascript-interop"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}