stride3d/stride · error · ArgumentException

The type must be an EntityComponent type.

Error message

The type must be an EntityComponent type.

What it means

GizmoComponentAttribute's constructor requires componentType to derive from (or implement) EntityComponent, otherwise it throws ArgumentException. Gizmos can only be attached to entity component types, so any other Type is rejected immediately at construction time.

Solutions

  1. Make the passed type inherit from EntityComponent (or pick the actual component class).
  2. Verify the generic type / Type object resolved by reflection is the component, not a model or processor type.
  3. If using typeof(), confirm the type is the concrete component (e.g. typeof(MyComponent) where MyComponent : EntityComponent).

Example fix

// before
new GizmoComponentAttribute(typeof(MyGizmoModel), true) // not an EntityComponent
// after
class MyComponent : EntityComponent { }
new GizmoComponentAttribute(typeof(MyComponent), true)
Defensive patterns

Strategy: type-guard

Validate before calling

if (!typeof(EntityComponent).IsAssignableFrom(componentType)) throw /* or log */ ;

Type guard

bool IsValidGizmoType(Type t) => t != null && typeof(EntityComponent).IsAssignableFrom(t);

Try / catch

try { var attr = new GizmoComponentAttribute(componentType, isMain); }
catch (ArgumentException e) { /* log invalid gizmo registration */ }

Prevention

When it happens

Trigger: new GizmoComponentAttribute(someType, isMainGizmo) where someType does not inherit from Stride.Engine.EntityComponent; also via a Type property assignment path that re-validates in the attribute constructor.

Common situations: Registering a gizmo for a plain C# class or a GameSystem instead of an EntityComponent subclass; typos or refactors replacing the component type with a wrapper/service type.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Engine/Engine/Gizmos/GizmoComponentAttribute.cs:25

namespace Stride.Engine.Gizmos
{
    /// <summary>
    /// Specifies for which component the associated gizmo class is.
    /// </summary>
    public class GizmoComponentAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GizmoComponentAttribute"/> class.
        /// </summary>
        /// <param name="componentType">The type of component the related gizmo class is associated with.</param>
        /// <param name="isMainGizmo">Indicates whether this gizmo is a main gizmo.</param>
        public GizmoComponentAttribute(Type componentType, bool isMainGizmo)
        {
            ComponentType = componentType;
            IsMainGizmo = isMainGizmo;
            if (!typeof(EntityComponent).IsAssignableFrom(componentType))
                throw new ArgumentException(@"The type must be an EntityComponent type.", nameof(componentType));
        }

        /// <summary>
        /// Gets or sets the type of component the related gizmo class is associated with.
        /// </summary>
        public Type ComponentType { get; set; }

        /// <summary>
        /// Gets or sets whether this gizmo is a main gizmo. An entity will display only one of its main gizmo, corresponding to the component
        /// that has the highest priority set in its <see cref="DisplayAttribute"/>.
        /// </summary>
        /// <remarks>
        /// Main gizmos will be entirely disposed instead of disabled if disabled in the gizmo settings
        /// </remarks>
        public bool IsMainGizmo { get; set; }
    }
}

View on GitHub (pinned to 96fad776d2)