{"record":{"id":"5ba4b29e8f7a9da7","repo":"dotnet/aspnetcore","slug":"cannot-provide-a-value-for-property-propertyname","errorCode":null,"errorMessage":"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.","messagePattern":"Cannot provide a value for property '(.+?)' on type '(.+?)'\\. The service provider does not implement '(.+?)' and therefore cannot provide keyed services\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/DefaultComponentPropertyActivator.cs","lineNumber":83,"sourceCode":"        {\n            return static (_, _) => { };\n        }\n\n        return Initialize;\n\n        // Return an action whose closure can write all the injected properties\n        // 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","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/DefaultComponentPropertyActivator.cs#L65-L101","documentation":"A property decorated with [Inject] specifies a Key, which requires keyed-service resolution. The active IServiceProvider does not implement IKeyedServiceProvider, so keyed resolution is impossible. Keyed services require .NET 8+ and a compatible host.","triggerScenarios":"[Inject(Key = \"myKey\")] on a component property, but the service provider (e.g. an older or custom container) does not implement IKeyedServiceProvider.","commonSituations":"Running on .NET 7 or earlier, a custom/legacy ServiceProvider, or a host that wraps the provider and loses the IKeyedServiceProvider interface.","solutions":["Upgrade to .NET 8+ and use the default host which supports keyed services.","Ensure the service provider passed to the renderer implements IKeyedServiceProvider.","Remove the Key from [Inject] and register the service as non-keyed if keyed resolution is unavailable."],"exampleFix":"// before\n[Inject(Key = \"admin\")] IUserService UserService { get; set; }\n// host pre-.NET8\n// after (option A)\n[Inject] IUserService UserService { get; set; }  // non-keyed registration","handlingStrategy":"validation","validationCode":"// Check provider capability before relying on keyed services.\nif (serviceProvider is not IKeyedServiceProvider && injectHasKey) { /* avoid keyed [Inject] or upgrade host */ }","typeGuard":"static bool SupportsKeyedServices(IServiceProvider sp) => sp is IKeyedServiceProvider;","tryCatchPattern":null,"preventionTips":["Target .NET 8+ when using [Inject(Key=...)].","Verify the host builds a ServiceProvider that implements IKeyedServiceProvider.","Prefer non-keyed [Inject] when running on older runtimes."],"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"}