{"record":{"id":"4947446e6a1dee7d","repo":"babalae/better-genshin-impact","slug":"paramname-js-array","errorCode":null,"errorMessage":"{paramName} 必须是集合或 JS Array","messagePattern":"(.+?) 必须是集合或 JS Array","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/BgiVision/BvPage.cs","lineNumber":160,"sourceCode":"    }\n\n\n    /// <summary>\n    /// 1080P 分辨率下点击坐标\n    /// </summary>\n    /// <param name=\"x\"></param>\n    /// <param name=\"y\"></param>\n    public void Click(double x, double y)\n    {\n        GameCaptureRegion.GameRegion1080PPosClick(x, y);\n    }\n\n    internal static List<T> ParseCollection<T>(object values, string paramName)\n    {\n        ArgumentNullException.ThrowIfNull(values, paramName);\n        if (values is string || values is not IEnumerable enumerable)\n        {\n            throw new ArgumentException($\"{paramName} 必须是集合或 JS Array\", paramName);\n        }\n\n        List<T> result = [];\n        foreach (var value in enumerable)\n        {\n            if (value is not T typedValue)\n            {\n                throw new ArgumentException($\"{paramName} 中的每个元素都必须是 {typeof(T).Name}\", paramName);\n            }\n\n            result.Add(typedValue);\n        }\n\n        if (result.Count == 0)\n        {\n            throw new ArgumentException($\"{paramName} 不能为空\", paramName);\n        }\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvPage.cs#L142-L178","documentation":"ParseCollection<T> is the bridge that turns a loosely-typed object (often a ClearScript JS array) into a strongly-typed List<T>. It throws ArgumentException when values is not IEnumerable, or is a string (which is IEnumerable<char> and must be excluded). This fires when the caller hands in a scalar, a JS object, or a plain string instead of an array/list.","triggerScenarios":"Calling GetByAnyText(\"确认\") with a single string instead of an array; passing a JS object {a:1}; passing a number; passing a string where a string[] is expected.","commonSituations":"JavaScript scripts invoking the BgiVision API passing a literal string rather than [\"...\"]; interop where a single value is wrapped incorrectly; Python/ClearScript returning a dict instead of a list.","solutions":["Pass an array/collection: GetByAnyText([\"确认\"]) or new[]{ \"确认\" }.","For JS callers, wrap single values in an array literal.","Verify the interop object type before the call when it originates from a dynamic source."],"exampleFix":"// before (JS)\nconst loc = page.getByAnyText(\"确认\");\n\n// after\nconst loc = page.getByAnyText([\"确认\"]);","handlingStrategy":"type-guard","validationCode":"// for JS/interop callers, ensure an array is passed\nif (values is string || values is not System.Collections.IEnumerable)\n    throw new InvalidOperationException(\"pass an array of strings\");","typeGuard":"static bool IsCollection(object? o) => o is not null && o is not string && o is System.Collections.IEnumerable;","tryCatchPattern":null,"preventionTips":["Always wrap single strings in an array when calling GetByAnyText from JS.","At interop boundaries, validate that the object is a non-string IEnumerable.","Keep a helper that coerces scalar->array for JS convenience."],"tags":["bgivision","interop","clearscript","argument-validation","js"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}