stride3d/stride · error · ArgumentException

Invalid required type

Error message

Invalid required type [{requiredType}]. Expecting only an EntityComponent type

What it means

The EntityProcessor constructor takes additionalTypes of components the processor requires and validates each is assignable to EntityComponent. It throws ArgumentException when a required type does not derive from EntityComponent, since processors only track component types.

Solutions

  1. Ensure every type in additionalTypes derives from Stride.Engine.EntityComponent
  2. Use typeof(YourComponent) for component types only; non-component dependencies go through Services instead
  3. Add an IsAssignableFrom check at the call site when types are dynamic

Example fix

// before
new MyProcessor(typeof(TransformComponent), typeof(Entity));
// after
new MyProcessor(typeof(TransformComponent), typeof(MyRequiredComponent));
Defensive patterns

Strategy: validation

Validate before calling

foreach (var t in additionalTypes)
    if (t == null || !typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()))
        throw new ArgumentException($"{t} is not an EntityComponent type");

Type guard

static bool IsValidRequiredType(Type t) => t != null && typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo());

Try / catch

try { var proc = new MyProcessor(additionalTypes); }
catch (ArgumentException ex) when (ex.Message.Contains("Expecting only an EntityComponent type")) { /* fix the type list */ }

Prevention

When it happens

Trigger: Defining a processor whose constructor is passed a Type (e.g. typeof(SomeService) or an interface/base type not derived from EntityComponent) in additionalTypes.

Common situations: Copy-pasting processor definitions and editing the type list with wrong types; passing entity/processor base types instead of component types; typos resolving to unrelated classes.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Engine/Engine/EntityProcessor.cs:67

        /// <exception cref="System.ArgumentNullException">If parameteters are null</exception>
        /// <exception cref="System.ArgumentException">If a type does not inherit from EntityComponent</exception>
        protected EntityProcessor([NotNull] Type mainComponentType, [NotNull] Type[] additionalTypes)
        {
            if (mainComponentType == null) throw new ArgumentNullException(nameof(mainComponentType));
            if (additionalTypes == null) throw new ArgumentNullException(nameof(additionalTypes));

            MainComponentType = mainComponentType;
            mainTypeInfo = MainComponentType.GetTypeInfo();

            RequiredTypes = new TypeInfo[additionalTypes.Length];

            // Check that types are valid
            for (var i = 0; i < additionalTypes.Length; i++)
            {
                var requiredType = additionalTypes[i];
                if (!typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(requiredType.GetTypeInfo()))
                {
                    throw new ArgumentException($"Invalid required type [{requiredType}]. Expecting only an EntityComponent type");
                }

                RequiredTypes[i] = requiredType.GetTypeInfo();
            }

            if (RequiredTypes.Length > 0)
            {
                componentTypesSupportedAsRequired = new Dictionary<TypeInfo, bool>();
            }

            UpdateProfilingKey = new ProfilingKey(GameProfilingKeys.GameUpdate, GetType().Name);
            DrawProfilingKey = new ProfilingKey(GameProfilingKeys.GameDraw, GetType().Name);
        }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="EntityProcessor"/> is enabled.
        /// </summary>
        public bool Enabled { get; set; } = true;

View on GitHub (pinned to 96fad776d2)