dotnet/aspnetcore · error · ArgumentNullException
propertyActivator
Error message
propertyActivator
What it means
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.
Source
Thrown at src/Components/Components/src/ComponentFactory.cs:37
private static readonly ConcurrentDictionary<Type, IComponentRenderMode?> _cachedComponentTypeRenderModes = new();
static ComponentFactory()
{
if (HotReloadManager.IsSupported)
{
HotReloadManager.Default.OnDeltaApplied += ClearCache;
}
}
private readonly IComponentActivator _componentActivator;
private readonly IComponentPropertyActivator _propertyActivator;
private readonly Renderer _renderer;
public ComponentFactory(IComponentActivator componentActivator, IComponentPropertyActivator propertyActivator, Renderer renderer)
{
_componentActivator = componentActivator ?? throw new ArgumentNullException(nameof(componentActivator));
_propertyActivator = propertyActivator ?? throw new ArgumentNullException(nameof(propertyActivator));
_renderer = renderer ?? throw new ArgumentNullException(nameof(renderer));
}
public static void ClearCache() => _cachedComponentTypeRenderModes.Clear();
private static IComponentRenderMode? GetComponentTypeRenderMode([DynamicallyAccessedMembers(Component)] Type componentType)
{
// Unfortunately we can't use 'GetOrAdd' here because the DynamicallyAccessedMembers annotation doesn't flow through to the
// callback, so it becomes an IL2111 warning. The following is equivalent and thread-safe because it's a ConcurrentDictionary
// and it doesn't matter if we build a cache entry more than once.
if (!_cachedComponentTypeRenderModes.TryGetValue(componentType, out var renderMode))
{
renderMode = componentType.GetCustomAttribute<RenderModeAttribute>()?.Mode;
_cachedComponentTypeRenderModes.TryAdd(componentType, renderMode);
}
return renderMode;
}View on GitHub (pinned to 3600ca084e)
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.
Example fix
// before var factory = new ComponentFactory(activator, null, renderer); // after var factory = new ComponentFactory(activator, new DefaultComponentPropertyActivator(sp), renderer);
Defensive patterns
Strategy: validation
Validate before calling
ArgumentNullException.ThrowIfNull(propertyActivator); var factory = new ComponentFactory(componentActivator, propertyActivator, renderer);
Prevention
- Register IComponentPropertyActivator in DI.
- Use ArgumentNullException.ThrowIfNull before manual construction.
- In tests, pass DefaultComponentPropertyActivator instead of null.
When it happens
Trigger: Calling new ComponentFactory(componentActivator, null, renderer), or DI failing to resolve IComponentPropertyActivator.
Common situations: DI misconfiguration, manual construction in tests with a null mock, or a trimmed/partial service provider missing the registration.
Related errors
- componentActivator
- The component type '{componentType}' has a fixed rendermode
- The component activator returned a null value for a componen
- Cannot provide a value for property '{propertyName}' on type
- Cannot provide a value for property '{propertyName}' on type
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/829533034b7929cc.
Report an issue: GitHub.