Reputation: 87
I was trying to implement the following article: https://github.com/App-vNext/Polly/wiki/Polly-and-HttpClientFactory
I'm using HttpFactory in my Worker Service project to get some data, I want to make it more robust using Microsoft.Extensions.Http.Polly
.
The problem is that I keep getting the following error even though the package is installed :
Error CS0234
The type or namespace name 'Polly' does not exist in the namespace 'Microsoft.Extensions.Http' (are you missing an assembly reference?)
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SolutionLibrary\SolutionLibrary.csproj" />
</ItemGroup>
</Project>
What did I miss ?
Upvotes: 0
Views: 2262
Reputation: 38795
You're missing that package or assembly name isn't the same as the namespace(s) the code lives in. Although it's often convention that a package named "Foo" will occupy the namespace "Foo" and related namespaces will be something like "Foo.Bar", etc. it's not the only way to do this.
You can find out what namespaces and classes a library makes available to you by using the Object Browser:
Clicking on "PollyHttpClientBuilderExtensions" shows the methods made available by the class:
And, as the name suggests, the method signature displayed in the lower pane indicates that the selected method is an extension method on IHttpClientBuilder
, so you have to use it in conjunction with services.AddHttpClient()
. It seems likely that this is the one you want to access in your code. Therefore, you should include the following using
:
using Microsoft.Extensions.DependencyInjection;
Upvotes: 2