{"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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/DefaultComponentPropertyActivator.cs#L72-L107","documentation":"The service provider implements IKeyedServiceProvider, but GetKeyedService returned null for the requested type+key pair. No matching keyed registration exists, which means [Inject(Key=...)] cannot be satisfied.","triggerScenarios":"[Inject(Key = \"myKey\")] on a property, but no services.AddKeyedSingleton<T,TImpl>(\"myKey\") (or scoped/transient) registration exists.","commonSituations":"Key typo between registration and injection, forgot to register the keyed service, key type mismatch (e.g. string vs enum), or conditional registration not met.","solutions":["Register the keyed service with the exact key: services.AddKeyedSingleton<T, TImpl>(\"myKey\").","Verify the key value and type match between registration and [Inject(Key=...)].","Check registration lifetime matches the consuming scope."],"exampleFix":"// before\n[Inject(Key = \"admin\")] IUserService Svc { get; set; }\n// no registration\n// after\nbuilder.Services.AddKeyedSingleton<IUserService, AdminUserService>(\"admin\");","handlingStrategy":"validation","validationCode":"// Resolve the keyed service at startup to fail fast if missing.\nvar svc = sp.GetKeyedService<IMyService>(\"myKey\");\nif (svc is null) throw new InvalidOperationException(\"Keyed service 'myKey' not registered.\");","typeGuard":"static bool IsKeyedRegistered(IServiceProvider sp, Type t, object key) => sp is IKeyedServiceProvider ksp && ksp.GetKeyedService(t, key) is not null;","tryCatchPattern":null,"preventionTips":["Register keyed services with the exact key used in [Inject(Key=...)].","Write a startup validation that resolves each keyed injection.","Keep keys in shared constants to avoid string-typo drift."],"tags":["blazor","di","keyed-services","inject"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}