[Bug]: Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'MudBlazor.Extensions.Services.MudExFileService'
Closed this issue · 3 comments
jaypalexa commented
Contact Details
What happened?
After upgrading to 1.7.68, we are now seeing the following exception at application startup. (When we roll back to 1.7.67, we do not see this exception).
System.AggregateException
HResult=0x80131500
Message=Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: MudBlazor.Extensions.Services.MudExFileService Lifetime: Transient ImplementationType: MudBlazor.Extensions.Services.MudExFileService': Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'MudBlazor.Extensions.Services.MudExFileService'.) (Error while validating the service descriptor 'ServiceType: MudBlazor.Extensions.Services.MudExFileService Lifetime: Transient ImplementationType: MudBlazor.Extensions.Services.MudExFileService': Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'MudBlazor.Extensions.Services.MudExFileService'.)
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
at Program.<Main>$(String[] args) in C:\temp\TestApp3\Program.cs:line 11
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
InvalidOperationException: Error while validating the service descriptor 'ServiceType: MudBlazor.Extensions.Services.MudExFileService Lifetime: Transient ImplementationType: MudBlazor.Extensions.Services.MudExFileService': Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'MudBlazor.Extensions.Services.MudExFileService'.
Inner Exception 2:
InvalidOperationException: Unable to resolve service for type 'System.Net.Http.HttpClient' while attempting to activate 'MudBlazor.Extensions.Services.MudExFileService'.
using MudBlazor.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpContextAccessor();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddMudExtensions();
builder.Services.AddMudServicesWithExtensions();
var app = builder.Build();
app.UseDeveloperExceptionPage();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();
Expected Behavior
No exception
Screenshots
What application type are you referring to?
ServerRendered
Custom Application Type
No response
MudBlazor.Extension Version
1.7.68
MudBlazor Version
6.10.0
What browser are you using?
Chrome
Sample Solution
Pull Request
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
fgilde commented
You're right, I'm so sorry my mistake. Will change it asap if you need a quickfix you can just register one in your Startup
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
fgilde commented
Solved in 1.7.69
jaypalexa commented
Thank you once again, Florian, for your quick attention. All seems well now in 1.7.69.