{"record":{"id":"7f5c5951518d0706","repo":"dotnet/aspnetcore","slug":"componentactivator","errorCode":null,"errorMessage":"componentActivator","messagePattern":"componentActivator","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/ComponentFactory.cs","lineNumber":36,"sourceCode":"        isDisabled;\n\n    private static readonly ConcurrentDictionary<Type, IComponentRenderMode?> _cachedComponentTypeRenderModes = new();\n\n    static ComponentFactory()\n    {\n        if (HotReloadManager.IsSupported)\n        {\n            HotReloadManager.Default.OnDeltaApplied += ClearCache;\n        }\n    }\n\n    private readonly IComponentActivator _componentActivator;\n    private readonly IComponentPropertyActivator _propertyActivator;\n    private readonly Renderer _renderer;\n\n    public ComponentFactory(IComponentActivator componentActivator, IComponentPropertyActivator propertyActivator, Renderer renderer)\n    {\n        _componentActivator = componentActivator ?? throw new ArgumentNullException(nameof(componentActivator));\n        _propertyActivator = propertyActivator ?? throw new ArgumentNullException(nameof(propertyActivator));\n        _renderer = renderer ?? throw new ArgumentNullException(nameof(renderer));\n    }\n\n    public static void ClearCache() => _cachedComponentTypeRenderModes.Clear();\n\n    private static IComponentRenderMode? GetComponentTypeRenderMode([DynamicallyAccessedMembers(Component)] 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 (!_cachedComponentTypeRenderModes.TryGetValue(componentType, out var renderMode))\n        {\n            renderMode = componentType.GetCustomAttribute<RenderModeAttribute>()?.Mode;\n            _cachedComponentTypeRenderModes.TryAdd(componentType, renderMode);\n        }\n\n        return renderMode;","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/ComponentFactory.cs#L18-L54","documentation":"ComponentFactory's constructor requires a non-null IComponentActivator. This is a standard null-guard precondition (ArgumentNullException) ensuring the factory can always activate components.","triggerScenarios":"Calling new ComponentFactory(null, propertyActivator, renderer), or DI failing to resolve IComponentActivator and passing null.","commonSituations":"DI misconfiguration where IComponentActivator is not registered, manual construction in tests with a null mock, or a custom DI container that returns null for unregistered services.","solutions":["Ensure IComponentActivator is registered in the service collection.","Pass a non-null instance, e.g. DefaultComponentActivator, when constructing manually.","Verify DI resolution before constructing the factory in test setup."],"exampleFix":"// before\nvar factory = new ComponentFactory(null, propActivator, renderer);\n// after\nvar factory = new ComponentFactory(new DefaultComponentActivator(sp), propActivator, renderer);","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(componentActivator);\nvar factory = new ComponentFactory(componentActivator, propertyActivator, renderer);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register IComponentActivator in DI when using the default Blazor host.","Use ArgumentNullException.ThrowIfNull before constructing ComponentFactory manually.","In tests, pass DefaultComponentActivator rather than a null mock."],"tags":["blazor","di","component-factory","argument-null"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}