{"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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/DefaultComponentActivator.cs#L12-L48","documentation":"DefaultComponentActivator.CreateInstance requires the supplied type to implement IComponent, the fundamental Blazor contract. Passing a plain class, record, or any non-component type is rejected with ArgumentException.","triggerScenarios":"Calling CreateInstance with a Type that does not implement IComponent, e.g. via DynamicComponent's Type parameter set to a non-component, or reflection-driven activation with an arbitrary type.","commonSituations":"DynamicComponent bound to a type resolved at runtime that is not a component, or a custom activator forwarding arbitrary types to the default activator.","solutions":["Ensure the type implements IComponent (inherit from ComponentBase or implement IComponent directly).","Validate typeof(IComponent).IsAssignableFrom(type) before activating.","If using DynamicComponent, guard the Type with a null/contract check."],"exampleFix":"// before\nDynamicComponent with Type = typeof(SomePlainClass)\n// after\nDynamicComponent with Type = typeof(SomeRazorComponent)  // SomeRazorComponent : ComponentBase","handlingStrategy":"type-guard","validationCode":"if (!typeof(IComponent).IsAssignableFrom(componentType))\n    throw new ArgumentException($\"{componentType} is not an IComponent.\");","typeGuard":"static bool IsComponent(Type t) => typeof(IComponent).IsAssignableFrom(t);","tryCatchPattern":null,"preventionTips":["Validate typeof(IComponent).IsAssignableFrom before activating or assigning to DynamicComponent.Type.","Constrain DynamicComponent Type sources to known component assemblies.","Unit-test that candidate types implement IComponent."],"tags":["blazor","component-activator","dynamic-component","type-validation"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}