dotnet/aspnetcore · error · InvalidOperationException

Cannot provide a value for property

Error message

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

What it means

A non-keyed [Inject] property could not be resolved: the service type is not registered in the DI container. Blazor requires every injected dependency to be available at component activation.

Solutions

  1. Register the service type in Program.cs (e.g. builder.Services.AddScoped<IMyService, MyService>()).
  2. Verify the service lifetime is compatible with the component's scope.
  3. Check that @inject directives and the registered types match exactly.

Example fix

// before
[Inject] IMyService Svc { get; set; }
// no registration
// after
builder.Services.AddScoped<IMyService, MyService>();
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast at startup if a required service is missing.
var svc = sp.GetService<IMyService>();
if (svc is null) throw new InvalidOperationException("IMyService not registered.");

Type guard

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

Prevention

When it happens

Trigger: [Inject] on a property whose service type was never registered via AddScoped/AddTransient/AddSingleton in the application's service collection.

Common situations: Forgot to register the service in Program.cs, registered in the wrong container (server vs client Blazor), scope mismatch (singleton injecting scoped), or missing a namespace/extension method call.

Related errors


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

Appendix: 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 3600ca084e)