{"record":{"id":"1ddd33a979800e7e","repo":"stride3d/stride","slug":"there-must-be-three-and-only-three-input-values-for-int3","errorCode":null,"errorMessage":"There must be three and only three input values for Int3.","messagePattern":"There must be three and only three input values for Int3\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Mathematics/Int3.cs","lineNumber":138,"sourceCode":"    /// <param name=\"z\">Initial value for the Z component of the vector.</param>\n    public Int3(Vector2 value, int z)\n    {\n        X = (int)value.X;\n        Y = (int)value.Y;\n        Z = z;\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"Int3\"/> 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 Int3(int[] values)\n    {\n        ArgumentNullException.ThrowIfNull(values);\n        if (values.Length != 3)\n            throw new ArgumentOutOfRangeException(nameof(values), \"There must be three and only three input values for Int3.\");\n\n        X = values[0];\n        Y = values[1];\n        Z = values[2];\n    }\n\n    /// <summary>\n    /// Gets or sets the component at the specified index.\n    /// </summary>\n    /// <value>The value of the X, Y, or Z component, depending on the index.</value>\n    /// <param name=\"index\">The index of the component to access. Use 0 for the X component, 1 for the Y component, and 2 for the Z component.</param>\n    /// <returns>The value of the component at the specified index.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">Thrown when the <paramref name=\"index\"/> is out of the range [0, 2].</exception>\n    public int this[int index]\n    {\n        readonly get\n        {\n            return index switch","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Mathematics/Int3.cs#L120-L156","documentation":"The Int3(values) array constructor requires the input array to contain exactly three elements and throws when the length differs. It is a length guard on the constructor input: an array with fewer than three elements leaves X/Y/Z undefined, and a longer one is a caller mistake, so both fire the error.","triggerScenarios":"Calling new Int3(int[]) with an array of length 0, 1, 2, 4, etc. — e.g. splitting a line that produced an extra token, or passing a 4-element RGBA/color array to construct a position.","commonSituations":"Parsing CSV/obj/config data with inconsistent tuple sizes; mixing 3D position (3) and quaternion/color (4) arrays; trailing empty string from Split making 4 tokens.","solutions":["Validate values.Length == 3 before calling the constructor","Fix the parsing/splitting code that produced the wrong-size array","If the source has 4 components, slice explicitly: new Int3(arr[0], arr[1], arr[2])"],"exampleFix":"// before\nvar v = new Int3(File.ReadAllLines(...)[0].Split(',').Select(int.Parse).ToArray()); // may be wrong length\n// after\nvar vals = line.Split(',').Select(int.Parse).ToArray();\nif (vals.Length != 3) throw new FormatException($\"Expected 3 values, got {vals.Length}\");\nvar v = new Int3(vals);","handlingStrategy":"validation","validationCode":"if (values is null || values.Length != 3)\n    throw new ArgumentException(\"Int3 requires exactly 3 elements\", nameof(values));\nvar v = new Int3(values);","typeGuard":"static bool IsValidInt3Source(int[]? values) => values is { Length: 3 };","tryCatchPattern":"try { var v = new Int3(values); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"values\")\n{\n    // log values.Length and handle malformed input\n}","preventionTips":["Check length == 3 before constructing from parsed data","Trim trailing separators before Split to avoid empty trailing tokens","Prefer new Int3(x, y, z) over array construction when possible"],"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"}