{"record":{"id":"1aad20c32b839811","repo":"stride3d/stride","slug":"there-must-be-two-and-only-two-input-values-for-int2","errorCode":null,"errorMessage":"There must be two and only two input values for Int2.","messagePattern":"There must be two and only two input values for Int2\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Int2.cs","lineNumber":122,"sourceCode":"    /// </summary>\n    /// <param name=\"value\">A vector containing the values with which to initialize the X and Y components.</param>\n    public Int2(Vector2 value)\n    {\n        X = (int)value.X;\n        Y = (int)value.Y;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Int2\"/> struct.\n    /// </summary>\n    /// <param name=\"values\">The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"values\"/> is <c>null</c>.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when <paramref name=\"values\"/> contains more or less than three elements.</exception>\n    public Int2(int[] values)\n    {\n        ArgumentNullException.ThrowIfNull(values);\n        if (values.Length != 2)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be two and only two input values for Int2.\");\n\n        X = values[0];\n        Y = values[1];\n    }\n\n    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X or Y component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the X component and 1 for the Y component.</param>\n    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref=\"System.ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 1].</exception>\n    public int this[int index]\n    {\n        readonly get\n        {\n            return index switch\n            {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Int2.cs#L104-L140","documentation":"Int2's array constructor requires the input array to contain exactly two elements, one for X and one for Y. The library throws ArgumentOutOfRangeException when values.Length != 2 so that partially-filled components are never silently zeroed. It is thrown after a null check, so the array was non-null but the wrong size.","triggerScenarios":"Calling new Int2(int[]) with an array of length 0, 1, 3, or more — e.g. parsing a config string with Split(',') that yielded an extra token, or passing a 3/4-element color or vector array where a 2-element one was expected.","commonSituations":"Deserializing data files whose vector entries have inconsistent element counts; mixing up Int2 with Int3/Int4 arrays; off-by-one splits producing a trailing empty token.","solutions":["Ensure the array passed to new Int2(...) has exactly 2 elements before constructing","Check the source of the array (split/parsing code) for stray empty or extra tokens","If the data may have 3+ components (e.g. RGB), explicitly slice: new Int2(arr[0], arr[1]) or arr.Take(2).ToArray()"],"exampleFix":"// before\nvar parts = line.Split(',');\nvar v = new Int2(parts.Select(int.Parse).ToArray()); // crashes if 3 tokens\n// after\nvar parts = line.Split(',');\nif (parts.Length != 2) throw new FormatException($\"Expected 2 values, got {parts.Length}\");\nvar v = new Int2(parts.Select(int.Parse).ToArray());","handlingStrategy":"validation","validationCode":"if (values is null || values.Length != 2)\n    throw new ArgumentException(\"Int2 requires exactly 2 elements\", nameof(values));\nvar v = new Int2(values);","typeGuard":"static bool IsValidInt2Source(int[]? values) => values is { Length: 2 };","tryCatchPattern":"try { var v = new Int2(values); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"values\")\n{\n    // log values.Length and fall back / report bad data\n}","preventionTips":["Always check array length before constructing vectors from arrays","Use constructor overloads new Int2(x, y) when components come from separate variables","Guard Split() parsing against trailing separators producing empty tokens"],"tags":["csharp","stride","mathematics","argument-out-of-range"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}