Aspnetcore: [Blazor] IServiceCollection does not contain a definition for AddBaseAddressHttpClient

Created on 30 Apr 2020  路  2Comments  路  Source: dotnet/aspnetcore

I upgraded a WASM app to 3.2.0-rc1.20223.4 and now the following code no longer compiles.

public static async Task Main(string[] args)
{
    var builder = WebAssemblyHostBuilder.CreateDefault(args);
    builder.Services.AddBaseAddressHttpClient();

This is not mentioned in the upgrade notes. What is the solution?

Answered Resolved area-blazor

Most helpful comment

It's in the notes of the previous preview.

https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-4-release-now-available/

Replace calls to AddBaseAddressHttpClient in Program.cs with builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });.

All 2 comments

It's in the notes of the previous preview.

https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-4-release-now-available/

Replace calls to AddBaseAddressHttpClient in Program.cs with builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });.

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Was this page helpful?
0 / 5 - 0 ratings