dotnet/aspnetcore · error · InvalidOperationException

Cannot provide a value for property '{propertyName}' on type

Error message

Cannot provide a value for property '{propertyName}' on type '{type.FullName}'. There is no registered service of type '{propertyType}'.

What it means

Thrown by DefaultComponentPropertyActivator when a component property uses [Inject] (non-keyed) and no service of the property's type is registered in DI. GetService returns null and the exception fires at DefaultComponentPropertyActivator.cs:96-99. This is the most common Blazor DI error — a missing service registration.

Source

Thrown at src/Components/Components/src/DefaultComponentPropertyActivator.cs:97

                if (serviceKey is not null)
                {
                    if (serviceProvider is not IKeyedServiceProvider keyedServiceProvider)
                    {
                        throw new InvalidOperationException($"Cannot provide a value for property " +
                            $"'{propertyName}' on type '{type.FullName}'. The service provider " +
                            $"does not implement '{nameof(IKeyedServiceProvider)}' and therefore " +
                            $"cannot provide keyed services.");
                    }

                    serviceInstance = keyedServiceProvider.GetKeyedService(propertyType, serviceKey)
                        ?? throw new InvalidOperationException($"Cannot provide a value for property " +
                        $"'{propertyName}' on type '{type.FullName}'. There is no " +
                        $"registered keyed service of type '{propertyType}' with key '{serviceKey}'.");
                }
                else
                {
                    serviceInstance = serviceProvider.GetService(propertyType)
                        ?? throw new InvalidOperationException($"Cannot provide a value for property " +
                        $"'{propertyName}' on type '{type.FullName}'. There is no " +
                        $"registered service of type '{propertyType}'.");
                }

                setter.SetValue(component, serviceInstance);
            }
        }
    }
}

View on GitHub (pinned to 294cab2f9b)

Solutions

  1. Register the service in Program.cs / Startup: services.AddScoped<IMyService, MyService>().
  2. Verify the lifetime/scope matches the hosting model (Blazor Server uses scoped per-circuit; WASM uses singleton/scoped in client).
  3. Check for typos in the interface or that the correct assembly is referenced.

Example fix

// before
// component: [Inject] public IWeatherService Weather { get; set; }
// Program.cs: (nothing registered)

// after
builder.Services.AddScoped<IWeatherService, WeatherService>();
Defensive patterns

Strategy: validation

Validate before calling

if (serviceProvider.GetService(propertyType) is null)
    throw new InvalidOperationException($"No registered service of type {propertyType}.");

Type guard

static bool IsRegistered(IServiceProvider sp, Type t) => sp.GetService(t) is not null;

Prevention

When it happens

Trigger: A Blazor component with [Inject] public IMyService Service { get; set; } where IMyService was never registered (or registered in the wrong DI container/scope).

Common situations: Forgetting to call services.AddSingleton/Scoped/Transient for a service used by a component; registering in a different scope (e.g., scoped in a non-circuit host); typo in the interface type; missing an extension method call like AddHttpClient.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/42d303706a8ecd14. Report an issue: GitHub.