{"record":{"id":"c3dc766429869b15","repo":"dotnet/aspnetcore","slug":"cannot-provide-a-value-for-property-propertyname-c3dc76","errorCode":null,"errorMessage":"Cannot provide a value for property '{propertyName}' on type '{type.FullName}'. There is no registered keyed service of type '{propertyType}' with key '{serviceKey}'.","messagePattern":"Cannot provide a value for property '(.+?)' on type '(.+?)'\\. There is no registered keyed service of type '(.+?)' with key '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/DefaultComponentPropertyActivator.cs","lineNumber":90,"sourceCode":"        // without any further reflection calls (just typecasts)\n        void Initialize(IServiceProvider serviceProvider, IComponent component)\n        {\n            foreach (var (propertyName, propertyType, setter, serviceKey) in injectables)\n            {\n                object? serviceInstance;\n\n                if (serviceKey is not null)\n                {\n                    if (serviceProvider is not IKeyedServiceProvider keyedServiceProvider)\n                    {\n                        throw new InvalidOperationException($\"Cannot provide a value for property \" +\n                            $\"'{propertyName}' on type '{type.FullName}'. The service provider \" +\n                            $\"does not implement '{nameof(IKeyedServiceProvider)}' and therefore \" +\n                            $\"cannot provide keyed services.\");\n                    }\n\n                    serviceInstance = keyedServiceProvider.GetKeyedService(propertyType, serviceKey)\n                        ?? throw new InvalidOperationException($\"Cannot provide a value for property \" +\n                        $\"'{propertyName}' on type '{type.FullName}'. There is no \" +\n                        $\"registered keyed service of type '{propertyType}' with key '{serviceKey}'.\");\n                }\n                else\n                {\n                    serviceInstance = serviceProvider.GetService(propertyType)\n                        ?? throw new InvalidOperationException($\"Cannot provide a value for property \" +\n                        $\"'{propertyName}' on type '{type.FullName}'. There is no \" +\n                        $\"registered service of type '{propertyType}'.\");\n                }\n\n                setter.SetValue(component, serviceInstance);\n            }\n        }\n    }\n}\n","sourceCodeStart":72,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/DefaultComponentPropertyActivator.cs#L72-L107","documentation":"Thrown by DefaultComponentPropertyActivator when a component property uses [Inject(Key = someKey)] and the service provider supports keyed services, but no service of the requested type is registered with that specific key. GetKeyedService returns null, triggering the throw at DefaultComponentPropertyActivator.cs:89-92.","triggerScenarios":"Decorating a property with [Inject(Key = \"x\")] where no AddKeyedSingleton/Scoped/Transient<IMyService>(\"x\", ...) registration exists, or the key value doesn't match (case, type, or name mismatch).","commonSituations":"Renaming or removing a keyed registration without updating component attributes; key value mismatch (e.g., using an enum vs string); conditional registration that doesn't always add the key.","solutions":["Register the keyed service with the exact key and type: services.AddKeyedTransient<IMyService>(\"x\", ...).","Double-check the key value (string equality, case sensitivity) matches between registration and [Inject(Key=...)].","Ensure the service interface type matches the property type exactly."],"exampleFix":"// before\n[Inject(Key = \"readOnly\")] public IMyRepo Repo { get; set; }\n// no matching registration\n\n// after\nservices.AddKeyedScoped<IMyRepo>(\"readOnly\", (sp, k) => new ReadOnlyRepo());","handlingStrategy":"validation","validationCode":"if (serviceProvider is IKeyedServiceProvider ksp && ksp.GetKeyedService(propertyType, serviceKey) is null)\n    throw new InvalidOperationException($\"No keyed service {propertyType} with key {serviceKey}.\");","typeGuard":"static bool IsKeyRegistered(IServiceProvider sp, Type t, object key)\n    => sp is IKeyedServiceProvider ksp && ksp.GetKeyedService(t, key) is not null;","tryCatchPattern":null,"preventionTips":["Keep a single source of truth for keyed registration strings/objects.","Add a startup health check that resolves all keyed services used by components."],"tags":["blazor","di","keyed-services","injection","registration"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}