stride3d/stride · error · ArgumentException

Vector component 'Z' is invalid, only 'X' and 'Y' are…

Error message

Vector component 'Z' is invalid, only 'X' and 'Y' are supported.

What it means

A Vector2 has only X and Y components. The Vector2ComponentControlPointViewModel constructor validates the requested VectorComponent and throws ArgumentException when Z (or W) is requested, since there is no third component to edit on a Vector2 keyframe.

Solutions

  1. Only pass VectorComponent.X or VectorComponent.Y to this constructor
  2. Fix the factory loop to enumerate components based on the vector type (2, 3, or 4)
  3. If migrating from Vector3 to Vector2, drop the Z component view model
  4. Catch ArgumentException to skip invalid components in generic factories

Example fix

// before
new Vector2ComponentControlPointViewModel(curve, key, value, tangent, VectorComponent.Z);
// after
new Vector2ComponentControlPointViewModel(curve, key, value, tangent, VectorComponent.Y);
Defensive patterns

Strategy: validation

Validate before calling

if (component is VectorComponent.Z or VectorComponent.W)
    throw new ArgumentException("Only X/Y valid for Vector2", nameof(component));
var vm = new Vector2ComponentControlPointViewModel(curve, key, value, tangent, component);

Type guard

bool IsValidVector2Component(VectorComponent c) => c is VectorComponent.X or VectorComponent.Y;

Try / catch

try { vm = new Vector2ComponentControlPointViewModel(curve, key, value, tangent, component); }
catch (ArgumentException) { vm = null; /* skip component */ }

Prevention

When it happens

Trigger: Constructing new Vector2ComponentControlPointViewModel(curve, keyNode, valueNode, tangentTypeNode, VectorComponent.Z) — typically from generic factory code that iterates components X..W without knowing the vector dimension.

Common situations: Generic curve-creation code sharing a component loop across Vector2/3/4; refactoring a Vector3 editor to Vector2 while keeping the Z component entry; data-driven component lists from an asset.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/CurveEditor/ViewModels/ControlPoints/VectorComponentControlPointViewModel.cs:29

    public abstract class VectorComponentControlPointViewModel<TValue> : KeyFrameControlPointViewModel<TValue>
        where TValue : struct
    {
        protected VectorComponentControlPointViewModel([NotNull] CurveViewModelBase curve, [NotNull] IMemberNode keyNode, [NotNull] IMemberNode valueNode, [NotNull] IMemberNode tangentTypeNode, VectorComponent component) 
            : base(curve, keyNode, valueNode, tangentTypeNode)
        {
            Component = component;
            SynchronizePoint();
        }

        public VectorComponent Component { get; }
    }

    public sealed class Vector2ComponentControlPointViewModel : VectorComponentControlPointViewModel<Vector2>
    {
        public Vector2ComponentControlPointViewModel([NotNull] CurveViewModelBase curve, [NotNull] IMemberNode keyNode, [NotNull] IMemberNode valueNode, [NotNull] IMemberNode tangentTypeNode, VectorComponent component)
            : base(curve, keyNode, valueNode, tangentTypeNode, component)
        {
            if (component == VectorComponent.Z) throw new ArgumentException("Vector component 'Z' is invalid, only 'X' and 'Y' are supported.", nameof(component));
            if (component == VectorComponent.W) throw new ArgumentException("Vector component 'W' is invalid, only 'X' and 'Y' are supported.", nameof(component));
        }

        protected override double GetValue()
        {
            switch (Component)
            {
                case VectorComponent.X:
                    return ValueBinding.Value.X;

                case VectorComponent.Y:
                    return ValueBinding.Value.Y;

                case VectorComponent.Z:
                case VectorComponent.W:
                    throw new NotSupportedException();

                default:

View on GitHub (pinned to 96fad776d2)