{"record":{"id":"42d303706a8ecd14","repo":"dotnet/aspnetcore","slug":"cannot-provide-a-value-for-property-propertyname-42d303","errorCode":null,"errorMessage":"Cannot provide a value for property '{propertyName}' on type '{type.FullName}'. There is no registered service of type '{propertyType}'.","messagePattern":"Cannot provide a value for property '(.+?)' on type '(.+?)'\\. There is no registered service of type '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/DefaultComponentPropertyActivator.cs","lineNumber":97,"sourceCode":"                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":79,"sourceCodeEnd":107,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/DefaultComponentPropertyActivator.cs#L79-L107","documentation":"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.","triggerScenarios":"[Inject] on a property whose service type was never registered via AddScoped/AddTransient/AddSingleton in the application's service collection.","commonSituations":"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.","solutions":["Register the service type in Program.cs (e.g. builder.Services.AddScoped<IMyService, MyService>()).","Verify the service lifetime is compatible with the component's scope.","Check that @inject directives and the registered types match exactly."],"exampleFix":"// before\n[Inject] IMyService Svc { get; set; }\n// no registration\n// after\nbuilder.Services.AddScoped<IMyService, MyService>();","handlingStrategy":"validation","validationCode":"// Fail fast at startup if a required service is missing.\nvar svc = sp.GetService<IMyService>();\nif (svc is null) throw new InvalidOperationException(\"IMyService not registered.\");","typeGuard":"static bool IsRegistered(IServiceProvider sp, Type t) => sp.GetService(t) is not null;","tryCatchPattern":null,"preventionTips":["Register every [Inject] dependency in Program.cs.","Validate registrations at startup with a bootstrap check.","Ensure the consuming component's scope matches the service lifetime."],"tags":["blazor","di","dependency-injection","inject"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}