DEV Community

Rod Falanga (NM DOH)
Rod Falanga (NM DOH)

Posted on

How do I resolve a Cannot provide a value for property error?

I hope that I am posting my question in the correct place. This is my first time doing this, so please be patient.

I am working on my first ASP.NET Blazor application that is significant and doesn't just put a counter on the page. I've got two Blazor applications in this Visual Studio solution; one is a server-side Blazor app and is where it starts. The other is a WebAssembly Blazor app. In the server-side app it reads a cookie. I want to pass the information I get from the cookie to the WebAssembly. I've been using this tutorial to help. I believe it is useful, although it assumes that everything is in the same Visual Studio project. I've added this to the Program.cs file:

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7010/") });

builder.Services.AddSingleton<IAppData, AppData>();
Enter fullscreen mode Exit fullscreen mode

Then in the Home.razor file I've got this: @inject Services.AppData AppData. I thought that would be sufficient, but when I debug it I get this error:

InvalidOperationException: Cannot provide a value for property 'AppData' on type 'FPTimetrackCore.Components.Pages.Home'. There is no registered service of type 'FPTimetrackCore.Services.AppData'.
Microsoft.AspNetCore.Components.ComponentFactory+<>c_DisplayClass9_0.g_Initialize|1(IServiceProvider serviceProvider, IComponent component)

I don't understand why. I could use help, please.

Top comments (1)

Collapse
 
rodatdoh profile image
Rod Falanga (NM DOH)

The issue is I was using the concrete class AppData, whereas I could have been using the interface IAppData. The ASP.NET Dependency Injection didn't know how to handle the concrete class but does know how to handle the Interface.