{"record":{"id":"6406c14afdb1d6c4","repo":"stride3d/stride","slug":"the-type-must-be-an-entitycomponent-type","errorCode":null,"errorMessage":"The type must be an EntityComponent type.","messagePattern":"The type must be an EntityComponent type\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Engine/Gizmos/GizmoComponentAttribute.cs","lineNumber":25,"sourceCode":"\nnamespace Stride.Engine.Gizmos\n{\n    /// <summary>\n    /// Specifies for which component the associated gizmo class is.\n    /// </summary>\n    public class GizmoComponentAttribute : Attribute\n    {\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"GizmoComponentAttribute\"/> class.\n        /// </summary>\n        /// <param name=\"componentType\">The type of component the related gizmo class is associated with.</param>\n        /// <param name=\"isMainGizmo\">Indicates whether this gizmo is a main gizmo.</param>\n        public GizmoComponentAttribute(Type componentType, bool isMainGizmo)\n        {\n            ComponentType = componentType;\n            IsMainGizmo = isMainGizmo;\n            if (!typeof(EntityComponent).IsAssignableFrom(componentType))\n                throw new ArgumentException(@\"The type must be an EntityComponent type.\", nameof(componentType));\n        }\n\n        /// <summary>\n        /// Gets or sets the type of component the related gizmo class is associated with.\n        /// </summary>\n        public Type ComponentType { get; set; }\n\n        /// <summary>\n        /// Gets or sets whether this gizmo is a main gizmo. An entity will display only one of its main gizmo, corresponding to the component\n        /// that has the highest priority set in its <see cref=\"DisplayAttribute\"/>.\n        /// </summary>\n        /// <remarks>\n        /// Main gizmos will be entirely disposed instead of disabled if disabled in the gizmo settings\n        /// </remarks>\n        public bool IsMainGizmo { get; set; }\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Engine/Gizmos/GizmoComponentAttribute.cs#L7-L43","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the passed type inherit from EntityComponent (or pick the actual component class).","Verify the generic type / Type object resolved by reflection is the component, not a model or processor type.","If using typeof(), confirm the type is the concrete component (e.g. typeof(MyComponent) where MyComponent : EntityComponent)."],"exampleFix":"// before\nnew GizmoComponentAttribute(typeof(MyGizmoModel), true) // not an EntityComponent\n// after\nclass MyComponent : EntityComponent { }\nnew GizmoComponentAttribute(typeof(MyComponent), true)","handlingStrategy":"type-guard","validationCode":"if (!typeof(EntityComponent).IsAssignableFrom(componentType)) throw /* or log */ ;","typeGuard":"bool IsValidGizmoType(Type t) => t != null && typeof(EntityComponent).IsAssignableFrom(t);","tryCatchPattern":"try { var attr = new GizmoComponentAttribute(componentType, isMain); }\ncatch (ArgumentException e) { /* log invalid gizmo registration */ }","preventionTips":["Use a generic constraint `where T : EntityComponent` on registration helpers.","When using reflection, assert the resolved type derives from EntityComponent before constructing the attribute."],"tags":["gizmos","argument-exception","entity-component","type-check"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}