stride3d/stride · error · MissingMethodException

IEntityGizmo ' ' must have a constructor with exactly one…

Error message

IEntityGizmo '{gizmoType}' must have a constructor with exactly one parameter of type '{component.GetType()}'

What it means

Stride throws this MissingMethodException when creating an entity gizmo via Activator.CreateInstance(gizmoType, component): the resolved gizmo Type does not expose a constructor taking exactly one parameter assignable from the component instance. The gizmo contract requires a (component) ctor so Initialize can bind the gizmo to its component.

Solutions

  1. Add a public constructor with exactly one parameter of the component type (e.g. public MyGizmo(TransformComponent c) : base(c))
  2. Ensure the gizmo type registered in GizmoTypeDictionary matches the component type the ctor accepts
  3. If the component derives from a base, register the gizmo for the base type or add a ctor accepting the base component type
  4. Inspect the inner MissingMethodException to see which ctor signature was requested

Example fix

// before
class MyGizmo : IEntityGizmo {
  public MyGizmo() { }
}
// after
class MyGizmo : IEntityGizmo {
  public MyGizmo(TransformComponent component) { /* store component */ }
}
Defensive patterns

Strategy: type-guard

Validate before calling

var ctor = gizmoType.GetConstructor(new[] { component.GetType() });
if (ctor == null) throw new InvalidOperationException($"{gizmoType} lacks a ctor taking {component.GetType()}");

Type guard

static bool HasValidGizmoCtor(Type gizmoType, Type componentType) =>
    gizmoType.GetConstructor(new[] { componentType }) != null;

Try / catch

try { gizmo = (IEntityGizmo)Activator.CreateInstance(gizmoType, component); }
catch (MissingMethodException ex) { log.Error(ex); gizmo = null; }

Prevention

When it happens

Trigger: Registering a custom IEntityGizmo implementation in StrideDefaultAssetsPlugin.GizmoTypeDictionary whose class lacks a public single-argument constructor matching the component type, so Activator.CreateInstance(gizmoType, component) throws MissingMethodException, which is rethrown with this message.

Common situations: Writing a custom editor gizmo after copying a sample but changing the constructor signature; renaming/refactoring the component parameter; making the ctor internal/private; generic gizmo classes without the right ctor overload.

Related errors


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

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameComponentGizmoService.cs:329

            if (gizmoEntities == null)
            {
                gizmoEntities = new Dictionary<EntityComponent, IEntityGizmo>();
                entity.Tags.Set(GizmoEntitiesKey, gizmoEntities);
            }

            entity.Tags.TryGetValue(GizmoBase.NoGizmoKey, out bool noGizmo);
            if (noGizmo)
                return;

            // initialize the gizmo
            IEntityGizmo gizmo;
            try
            {
                gizmo = (IEntityGizmo)Activator.CreateInstance(gizmoType, component);
            }
            catch (MissingMethodException e)
            {
                throw new MissingMethodException($"{nameof(IEntityGizmo)} '{gizmoType}' must have a constructor with exactly one parameter of type '{component.GetType()}'", e);
            }
            gizmo.Initialize(game.Services, editorScene);

            gizmo.SizeFactor = GizmoSize;
            gizmo.Update();

            // register the gizmo into the scene entity and vice-versa
            gizmoEntities[component] = gizmo;
            sceneGizmos.Add(gizmo);
            if (!gizmoVisibilities.TryGetValue(gizmoType, out bool isVisible))
                isVisible = true;

            gizmo.IsEnabled = isVisible;
        }

        private void RemoveGizmo(IDictionary<EntityComponent, IEntityGizmo> gizmoEntities, IEntityGizmo gizmo, EntityComponent component)
        {
            sceneGizmos.Remove(gizmo);

View on GitHub (pinned to 96fad776d2)