stride3d/stride · error · ArgumentNullException

Value cannot be null. (Parameter 'values')

Error message

Value cannot be null. (Parameter 'values')

What it means

Thrown by the Vector3(float[] values) constructor when the values array is null. The constructor copies three elements (X, Y, Z) from the array, so null cannot be accepted. Documented as ArgumentNullException in the XML docs.

Solutions

  1. Pass a non-null array with exactly three floats: new Vector3(new float[]{x, y, z})
  2. Null-check before constructing and fall back to Vector3.Zero
  3. Fix the upstream parser/loader that produced a null array

Example fix

// before
var v = new Vector3(values); // values may be null
// after
var v = values != null && values.Length == 3 ? new Vector3(values) : Vector3.Zero;
Defensive patterns

Strategy: validation

Validate before calling

if (values == null || values.Length != 3)
    throw new ArgumentException("Vector3 requires a non-null 3-element array");

Type guard

static bool IsValidVector3Values(float[] values) => values != null && values.Length == 3;

Try / catch

try { var v = new Vector3(values); }
catch (ArgumentNullException) { var v = Vector3.Zero; }

Prevention

When it happens

Trigger: Calling new Vector3(null), typically with an array read from config, a file, or a deserializer that returned null.

Common situations: Config/JSON parsing yielding null arrays for missing keys; interop code passing null float buffers; factory methods returning null on failure.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/926aeb15f05b6995. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Mathematics/Vector3.cs:137

    /// <param name="value">A vector containing the values with which to initialize the X and Y components.</param>
    /// <param name="z">Initial value for the Z component of the vector.</param>
    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.

View on GitHub (pinned to 96fad776d2)