Reputation: 656
In VS 2019, I am trying to test using HttpClient
in a Blazor WebAssemply App. When creating the new Project, I selected the .Net Core 3.1
option. In the Program.cs, the HttpClient
service is registered as following:
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
Under the "framework" section, system.net.http
is listed.
We run into the problem of being unable to add @inject IHttpClientFactory http
to a new Razor Component. The error message was:
Error CS0246 The type or namespace name 'IHttpClientFactory' could not be found (are you missing a using directive or an assembly reference?)
The online doc at Microsoft site shows the IHttpClientFactory
is defined in theSystem.Net.Http
package. What is the root cause of the errors I got and how can I fix it?
Upvotes: 3
Views: 3555
Reputation: 542
You need to install the following Nuget package: Microsoft.Extensions.Http
Upvotes: 9