{"record":{"id":"0d2950e8a3bb5c73","repo":"stride3d/stride","slug":"the-type-must-be-of-entitycomponent","errorCode":null,"errorMessage":"The type must be of EntityComponent","messagePattern":"The type must be of EntityComponent","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Engine/EntityComponentAttributes.cs","lineNumber":47,"sourceCode":"        /// </summary>\n        /// <typeparam name=\"T\">Type of the component</typeparam>\n        /// <returns>The attributes for the specified type.</returns>\n        public static EntityComponentAttributes Get<T>() where T : EntityComponent\n        {\n            return GetInternal(typeof(T));\n        }\n\n        /// <summary>\n        /// Gets the attributes for the specified type.\n        /// </summary>\n        /// <param name=\"type\">The type of the component.</param>\n        /// <returns>The attributes for the specified type.</returns>\n        /// <exception cref=\"System.ArgumentNullException\"></exception>\n        /// <exception cref=\"System.ArgumentException\">The type must be of EntityComponent;type</exception>\n        public static EntityComponentAttributes Get([NotNull] Type type)\n        {\n            if (type == null) throw new ArgumentNullException(nameof(type));\n            if (!typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) throw new ArgumentException(@\"The type must be of EntityComponent\", nameof(type));\n            return GetInternal(type);\n        }\n\n        private static EntityComponentAttributes GetInternal([NotNull] Type type)\n        {\n            EntityComponentAttributes attributes;\n            lock (ComponentAttributes)\n            {\n                if (!ComponentAttributes.TryGetValue(type, out attributes))\n                {\n                    attributes = new EntityComponentAttributes(type.GetTypeInfo().GetCustomAttribute<AllowMultipleComponentsAttribute>() != null);\n                    ComponentAttributes.Add(type, attributes);\n                }\n            }\n            return attributes;\n        }\n    }\n}","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Engine/EntityComponentAttributes.cs#L29-L65","documentation":"EntityComponentAttributes.Get(Type) returns cached attribute metadata (e.g. AllowMultipleComponents) but only accepts types deriving from EntityComponent. It throws ArgumentNullException for null and ArgumentException for non-EntityComponent types, since attribute semantics are undefined for other classes.","triggerScenarios":"Calling EntityComponentAttributes.Get(typeof(SomeNonComponentClass)) or passing a null Type; also via EntityComponentCollection.ValidateItem which calls Get on item.GetType().","commonSituations":"Reflecting over arbitrary scene object types assuming they are components; passing an interface or base type unrelated to EntityComponent; registering custom components that accidentally do not inherit EntityComponent.","solutions":["Pass a Type that derives from Stride.Engine.EntityComponent","Add a null check before calling Get","If inspecting arbitrary types, filter with typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()) first"],"exampleFix":"// before\nvar attrs = EntityComponentAttributes.Get(someType);\n// after\nif (someType != null && typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(someType.GetTypeInfo()))\n    var attrs = EntityComponentAttributes.Get(someType);","handlingStrategy":"type-guard","validationCode":"if (type == null || !typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())) return null;","typeGuard":"static bool IsEntityComponentType(Type t) => t != null && typeof(EntityComponent).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo());","tryCatchPattern":"try { attrs = EntityComponentAttributes.Get(type); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"EntityComponent\")) { /* fall back to default attributes */ }","preventionTips":["Filter candidate types with IsAssignableFrom before querying attributes","Keep custom component classes inheriting EntityComponent","Never pass null Type to attribute lookups"],"tags":["csharp","stride","type-mismatch","reflection"],"backgroundTag":"type-mismatch","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"}