{"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/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/DefaultComponentPropertyActivator.cs#L65-L101","documentation":"Thrown by DefaultComponentPropertyActivator when a component property is decorated with [Inject(Key = someKey)] (requesting a keyed service) but the active IServiceProvider does not implement IKeyedServiceProvider. Blazor's default property injection calls GetService, but keyed injection requires a provider that supports GetKeyedService (added in .NET 8). The check is at DefaultComponentPropertyActivator.cs:79-87.","triggerScenarios":"Using [Inject(Key = \"myKey\")] on a Blazor component property when the DI container does not support keyed services (e.g., a custom IServiceProvider, an older hosting setup, or a test harness with a plain ServiceProvider).","commonSituations":"Using keyed services in a Blazor component but the host's service provider isn't the built-in DI container that supports keys; running component unit tests with a minimal service provider; misconfiguring the host provider factory.","solutions":["Ensure the application uses the default Microsoft.Extensions.DependencyInjection ServiceProvider which supports keyed services (.NET 8+).","If using a custom IServiceProvider, wrap it so it implements IKeyedServiceProvider.","If keyed services are unavailable, switch the [Inject] to a non-keyed registration."],"exampleFix":"// before\n[Inject(Key = \"primary\")] public IMyService Svc { get; set; }\n// host: services.AddSingleton(typeof(IMyService), defaultImpl); // no key, provider lacks keyed support\n\n// after — register as keyed and ensure default ServiceProvider\nservices.AddKeyedSingleton<IMyService>(\"primary\", (sp, k) => new PrimaryImpl());","handlingStrategy":"validation","validationCode":"if (serviceKey is not null && serviceProvider is not IKeyedServiceProvider)\n    throw new InvalidOperationException(\"Provider does not support keyed services.\");","typeGuard":"static bool SupportsKeyedServices(IServiceProvider sp) => sp is IKeyedServiceProvider;","tryCatchPattern":null,"preventionTips":["Use the default Microsoft.Extensions DI container (supports keyed services in .NET 8+).","Avoid [Inject(Key=...)] if your host uses a custom non-keyed provider."],"tags":["blazor","di","keyed-services","injection"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}