{"record":{"id":"829533034b7929cc","repo":"dotnet/aspnetcore","slug":"propertyactivator","errorCode":null,"errorMessage":"propertyActivator","messagePattern":"propertyActivator","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/ComponentFactory.cs","lineNumber":37,"sourceCode":"\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;\n    }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/ComponentFactory.cs#L19-L55","documentation":"ComponentFactory's constructor requires a non-null IComponentPropertyActivator. This is a null-guard precondition (ArgumentNullException) so that property injection always has an activator to delegate to.","triggerScenarios":"Calling new ComponentFactory(componentActivator, null, renderer), or DI failing to resolve IComponentPropertyActivator.","commonSituations":"DI misconfiguration, manual construction in tests with a null mock, or a trimmed/partial service provider missing the registration.","solutions":["Ensure IComponentPropertyActivator is registered in the service collection.","Pass a non-null instance such as DefaultComponentPropertyActivator when constructing manually.","Verify DI resolution in test setup before constructing the factory."],"exampleFix":"// before\nvar factory = new ComponentFactory(activator, null, renderer);\n// after\nvar factory = new ComponentFactory(activator, new DefaultComponentPropertyActivator(sp), renderer);","handlingStrategy":"validation","validationCode":"ArgumentNullException.ThrowIfNull(propertyActivator);\nvar factory = new ComponentFactory(componentActivator, propertyActivator, renderer);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register IComponentPropertyActivator in DI.","Use ArgumentNullException.ThrowIfNull before manual construction.","In tests, pass DefaultComponentPropertyActivator instead of null."],"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"}