{"record":{"id":"68f9520dd4e9c3d5","repo":"stride3d/stride","slug":"ientitygizmo-gizmotype-must-have-a-constructor-with-exactly","errorCode":null,"errorMessage":"IEntityGizmo '{gizmoType}' must have a constructor with exactly one parameter of type '{component.GetType()}'","messagePattern":"IEntityGizmo '(.+?)' must have a constructor with exactly one parameter of type '(.+?)'","errorType":"exception","errorClass":"MissingMethodException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameComponentGizmoService.cs","lineNumber":329,"sourceCode":"            if (gizmoEntities == null)\n            {\n                gizmoEntities = new Dictionary<EntityComponent, IEntityGizmo>();\n                entity.Tags.Set(GizmoEntitiesKey, gizmoEntities);\n            }\n\n            entity.Tags.TryGetValue(GizmoBase.NoGizmoKey, out bool noGizmo);\n            if (noGizmo)\n                return;\n\n            // initialize the gizmo\n            IEntityGizmo gizmo;\n            try\n            {\n                gizmo = (IEntityGizmo)Activator.CreateInstance(gizmoType, component);\n            }\n            catch (MissingMethodException e)\n            {\n                throw new MissingMethodException($\"{nameof(IEntityGizmo)} '{gizmoType}' must have a constructor with exactly one parameter of type '{component.GetType()}'\", e);\n            }\n            gizmo.Initialize(game.Services, editorScene);\n\n            gizmo.SizeFactor = GizmoSize;\n            gizmo.Update();\n\n            // register the gizmo into the scene entity and vice-versa\n            gizmoEntities[component] = gizmo;\n            sceneGizmos.Add(gizmo);\n            if (!gizmoVisibilities.TryGetValue(gizmoType, out bool isVisible))\n                isVisible = true;\n\n            gizmo.IsEnabled = isVisible;\n        }\n\n        private void RemoveGizmo(IDictionary<EntityComponent, IEntityGizmo> gizmoEntities, IEntityGizmo gizmo, EntityComponent component)\n        {\n            sceneGizmos.Remove(gizmo);","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/EntityHierarchyEditor/Game/EditorGameComponentGizmoService.cs#L311-L347","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a public constructor with exactly one parameter of the component type (e.g. public MyGizmo(TransformComponent c) : base(c))","Ensure the gizmo type registered in GizmoTypeDictionary matches the component type the ctor accepts","If the component derives from a base, register the gizmo for the base type or add a ctor accepting the base component type","Inspect the inner MissingMethodException to see which ctor signature was requested"],"exampleFix":"// before\nclass MyGizmo : IEntityGizmo {\n  public MyGizmo() { }\n}\n// after\nclass MyGizmo : IEntityGizmo {\n  public MyGizmo(TransformComponent component) { /* store component */ }\n}","handlingStrategy":"type-guard","validationCode":"var ctor = gizmoType.GetConstructor(new[] { component.GetType() });\nif (ctor == null) throw new InvalidOperationException($\"{gizmoType} lacks a ctor taking {component.GetType()}\");","typeGuard":"static bool HasValidGizmoCtor(Type gizmoType, Type componentType) =>\n    gizmoType.GetConstructor(new[] { componentType }) != null;","tryCatchPattern":"try { gizmo = (IEntityGizmo)Activator.CreateInstance(gizmoType, component); }\ncatch (MissingMethodException ex) { log.Error(ex); gizmo = null; }","preventionTips":["Give every IEntityGizmo a single public ctor accepting its component type","Unit-test gizmo/component registrations with Activator.CreateInstance checks","Keep gizmo ctor signatures in sync with GizmoTypeDictionary registrations"],"tags":["reflection","csharp","editor","gizmo","missing-constructor"],"backgroundTag":"missing-constructor","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}