{"record":{"id":"3c800d0389c070f7","repo":"dotnet/aspnetcore","slug":"the-type-componenttype-fullname-does-not-impleme","errorCode":null,"errorMessage":"The type {componentType.FullName} does not implement {nameof(IComponent)}.","messagePattern":"The type (.+?) does not implement (.+?)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/DefaultComponentActivator.cs","lineNumber":30,"sourceCode":"{\n    private static readonly ConcurrentDictionary<Type, ObjectFactory> _cachedComponentTypeInfo = new();\n\n    static DefaultComponentActivator()\n    {\n        if (HotReloadManager.IsSupported)\n        {\n            HotReloadManager.Default.OnDeltaApplied += ClearCache;\n        }\n    }\n\n    public static void ClearCache() => _cachedComponentTypeInfo.Clear();\n\n    /// <inheritdoc />\n    public IComponent CreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType)\n    {\n        if (!typeof(IComponent).IsAssignableFrom(componentType))\n        {\n            throw new ArgumentException($\"The type {componentType.FullName} does not implement {nameof(IComponent)}.\", nameof(componentType));\n        }\n\n        var factory = GetObjectFactory(componentType);\n\n        return (IComponent)factory(serviceProvider, []);\n    }\n\n    private static ObjectFactory GetObjectFactory([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type componentType)\n    {\n        // Unfortunately we can't use 'GetOrAdd' here because the DynamicallyAccessedMembers annotation doesn't flow through to the\n        // callback, so it becomes an IL2111 warning. The following is equivalent and thread-safe because it's a ConcurrentDictionary\n        // and it doesn't matter if we build a cache entry more than once.\n        if (!_cachedComponentTypeInfo.TryGetValue(componentType, out var factory))\n        {\n            factory = ActivatorUtilities.CreateFactory(componentType, Type.EmptyTypes);\n            _cachedComponentTypeInfo.TryAdd(componentType, factory);\n        }\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/DefaultComponentActivator.cs#L12-L48","documentation":"Thrown by DefaultComponentActivator.CreateInstance when the requested type does not implement IComponent. Blazor's component instantiation requires the type to be a valid component; passing a plain class, struct, or non-component type is an error. The check is at DefaultComponentActivator.cs:28-31.","triggerScenarios":"Passing a type to DynamicComponent's Type parameter, a custom activator, or a root component registration where the type does not implement IComponent (i.e., does not derive from ComponentBase or implement the interface directly).","commonSituations":"Passing a POCO or service class to DynamicComponent Type; wiring up a type by name that is a model not a component; reflection-based component loading that picks the wrong type.","solutions":["Ensure the type derives from ComponentBase (or implements IComponent directly).","Verify the Type passed to DynamicComponent is actually a Razor component, not a data model.","If loading types dynamically, filter candidates to those implementing IComponent."],"exampleFix":"// before\npublic class MyData { public int Id; } // not a component\n\n<DynamicComponent Type=\"@typeof(MyData)\" />\n\n// after\npublic class MyDataComponent : ComponentBase\n{\n    [Parameter] public int Id { get; set; }\n}\n\n<DynamicComponent Type=\"@typeof(MyDataComponent)\" />","handlingStrategy":"type-guard","validationCode":"if (!typeof(IComponent).IsAssignableFrom(componentType))\n    throw new ArgumentException($\"{componentType} does not implement IComponent.\");","typeGuard":"static bool IsValidComponentType(Type t) => typeof(IComponent).IsAssignableFrom(t);","tryCatchPattern":null,"preventionTips":["Validate candidate types with typeof(IComponent).IsAssignableFrom before passing to DynamicComponent.","Use a typed registry of known component types instead of open-ended reflection."],"tags":["blazor","di","component-activator","type-validation"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}