-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to register HttpClient service #31267
Comments
🍂🎁 Happy Holidays! ❄️⛄A green dinosaur 🦖 will be along shortly to assist. Stand-by ........ |
Hello @BrettSandham ... That's due to prerendering. The service won't be available on the server, so the error is thrown. It's covered in a general way here 👉 https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0#client-side-services-fail-to-resolve-during-prerendering For this specific case, there are two approaches to address it ...
Whichever direction you go, leave this issue open. I've been improving the guidance on these service scenarios, albeit slowly 🐌 due to all of the high priority issues that I'm still addressing. I'd like to use this issue to make further improvements to our coverage on this. When I work on this, I'll take a couple of approaches to improve coverage ...
This issue will close automatically later when the PR merges, and I should be able to reach this in early '24. We're all just about to bug out of here for the ⛄🏂❄️ holiday break, so I won't be able to reach this until then. Thanks for the issue and Happy New Year! 🎉🍾💃🕺🎆 |
Thank you! Was not expecting such a prompt response this time of the year. All the best to you and the whole team. |
Description
Hi
I'm sure this is an ID10T user issue!
I am trying to follow https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-8.0&pivots=webassemblyn and cannot register an HttpClient Service. Minimum steps :
builder.Services.AddScoped(sp =>
new HttpClient
{
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
});
@using System.Net.Http
@Inject HttpClient Http
Error
An unhandled exception occurred while processing the request.
InvalidOperationException: Cannot provide a value for property 'Http' on type 'HttpClientIssue.Client.Pages.Counter'. There is no registered service of type 'System.Net.Http.HttpClient'.
[Enter feedback here]
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/call-web-api?view=aspnetcore-8.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/call-web-api.md
Document ID
c7e59a08-1c60-32c2-75fd-33cb77ff7a5d
Article author
@guardrex
The text was updated successfully, but these errors were encountered: