stride3d/stride · error · ArgumentOutOfRangeException
There must be three and only three input values for Vector3.
Error message
There must be three and only three input values for Vector3.
What it means
Thrown by the Vector3(float[] values) constructor when the array length is not exactly 3. A Vector3 needs exactly one value per component (X, Y, Z), so fewer or more elements are invalid. ArgumentOutOfRangeException with message 'There must be three and only three input values for Vector3.'
Solutions
- Validate values.Length == 3 before constructing
- Trim or pad parsed data to exactly three components
- Use Vector3(x, y, z) component constructor when values are known individually
Example fix
// before
var v = new Vector3(tokens); // tokens.Length may differ from 3
// after
if (tokens.Length != 3) throw new FormatException("Expected 3 components");
var v = new Vector3(tokens[0], tokens[1], tokens[2]); Defensive patterns
Strategy: validation
Validate before calling
if (values == null || values.Length != 3)
throw new ArgumentException("Expected exactly 3 float components"); Type guard
static bool IsTriple(float[] values) => values != null && values.Length == 3;
Try / catch
try { var v = new Vector3(values); }
catch (ArgumentOutOfRangeException) { /* handle bad input length */ } Prevention
- Validate token/component counts when parsing vector strings
- Match array sizes to the target vector type (2 for Vector2, 3 for Vector3, 4 for Vector4)
- Add unit tests for parsed vector data shapes
When it happens
Trigger: new Vector3(new float[]{1,2}) or new Vector3(new float[]{1,2,3,4}) — any array whose Length != 3, often from parsing floats out of strings or files with wrong token counts.
Common situations: Parsing vector strings like '1 2' or '1 2 3 4' from config/CSV; reading 4-component RGBA arrays into a Vector3; schema drift between data files and code.
Related errors
- There must be three and only three input values for Color3.
- There must be 3 or 4 float[] values for Color4.
- There must be four and only four input values for ColorBGRA.
- There must be two and only two input values for Double2.
- There must be four and only four input values for Double4.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/c78194f0c3554226.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Mathematics/Vector3.cs:139
public Vector3(Vector2 value, float z)
{
X = value.X;
Y = value.Y;
Z = z;
}
/// <summary>
/// Initializes a new instance of the <see cref="Stride.Core.Mathematics.Vector3"/> struct.
/// </summary>
/// <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>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="values"/> is <c>null</c>.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="values"/> contains more or less than three elements.</exception>
public Vector3(float[] values)
{
if (values == null)
throw new ArgumentNullException(nameof(values));
if (values.Length != 3)
throw new ArgumentOutOfRangeException(nameof(values), "There must be three and only three input values for Vector3.");
X = values[0];
Y = values[1];
Z = values[2];
}
/// <summary>
/// Gets a value indicting whether this instance is normalized.
/// </summary>
public readonly bool IsNormalized
{
get { return MathF.Abs((X * X) + (Y * Y) + (Z * Z) - 1f) < MathUtil.ZeroTolerance; }
}
/// <summary>
/// Gets or sets the component at the specified index.
/// </summary>
/// <value>The value of the X, Y, or Z component, depending on the index.</value>View on GitHub (pinned to 96fad776d2)