{"record":{"id":"1cedacc460575ee0","repo":"babalae/better-genshin-impact","slug":"paramname-typeof-t-name","errorCode":null,"errorMessage":"{paramName} 中的每个元素都必须是 {typeof(T).Name}","messagePattern":"(.+?) 中的每个元素都必须是 (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/BgiVision/BvPage.cs","lineNumber":168,"sourceCode":"    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\n        return result;\n    }\n}\n","sourceCodeStart":150,"sourceCodeEnd":182,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/BgiVision/BvPage.cs#L150-L182","documentation":"Inside ParseCollection<T>, after confirming values is enumerable, each element is checked with 'is not T'. If any element is not of the expected type T (e.g. not string), ArgumentException is thrown. This protects the generic helper used by GetByAnyText and similar APIs from silently storing mismatched types that would fail later during OCR matching.","triggerScenarios":"GetByAnyText(new object[]{ \"确认\", 123 }) where 123 is not a string; a JS array mixing strings and numbers like [\"OK\", 5]; passing a List<int> where List<string> is expected.","commonSituations":"Heterogeneous arrays from untyped interop; config files deserialized into object[]; JS scripts mixing string and numeric literals.","solutions":["Normalize every element to the target type before calling: texts.Select(o => o?.ToString()).","Ensure the source collection is declared with the correct element type.","Validate element types at the interop boundary and coerce or reject early."],"exampleFix":"// before\nvar loc = page.GetByAnyText(new object[] { \"确认\", 123 });\n\n// after\nvar loc = page.GetByAnyText(\n    new object[] { \"确认\", 123 }.Select(o => o.ToString()).ToArray());","handlingStrategy":"validation","validationCode":"// coerce heterogeneous interop arrays to the target type\nvar safe = raw.OfType<object>().Select(o => o?.ToString() ?? string.Empty).ToArray();\nvar loc = page.GetByAnyText(safe);","typeGuard":"static bool AllOfType<T>(System.Collections.IEnumerable e) => e.Cast<object>().All(o => o is T);","tryCatchPattern":null,"preventionTips":["Normalize element types at the interop boundary before calling ParseCollection-backed APIs.","Type your collections (string[]) instead of object[] where possible.","Reject mixed-type arrays early in JS glue code."],"tags":["bgivision","interop","type-mismatch","argument-validation"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}