HttpClient.Resilience.Analyzers
0.1.142
dotnet add package HttpClient.Resilience.Analyzers --version 0.1.142
NuGet\Install-Package HttpClient.Resilience.Analyzers -Version 0.1.142
<PackageReference Include="HttpClient.Resilience.Analyzers" Version="0.1.142"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="HttpClient.Resilience.Analyzers" Version="0.1.142" />
<PackageReference Include="HttpClient.Resilience.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add HttpClient.Resilience.Analyzers --version 0.1.142
#r "nuget: HttpClient.Resilience.Analyzers, 0.1.142"
#:package HttpClient.Resilience.Analyzers@0.1.142
#addin nuget:?package=HttpClient.Resilience.Analyzers&version=0.1.142
#tool nuget:?package=HttpClient.Resilience.Analyzers&version=0.1.142
<p align="center"> <img src="https://raw.githubusercontent.com/georgepwall1991/HttpClient.Resilience.Analyzers/main/assets/logo.png" alt="HttpClient.Resilience.Analyzers logo — Roslyn analyzers for HttpClient and IHttpClientFactory" width="160"> </p>
HttpClient Resilience Analyzers — IHttpClientFactory, Polly, and Http.Resilience
Compile-time Roslyn analyzers and code fixes for .NET HttpClient, IHttpClientFactory, AddHttpClient typed clients, Polly, and Microsoft.Extensions.Http.Resilience.
Catch outbound HTTP reliability bugs at build time—socket exhaustion, missing PooledConnectionLifetime, DI lifetime leaks, stacked resilience handlers, unsafe POST retries, undisposed responses, and dropped cancellation tokens—before production, not at runtime.
Analyzer-only package: no runtime dependency is added to your application.
The problem
HttpClient misuse often compiles cleanly and looks fine in review. Socket exhaustion, stale DNS, double retries on POST, typed clients held by singletons, and undisposed ResponseHeadersRead streams show up under load—after deploy.
What it catches
- Per-request
new HttpClient()and long-lived clients withoutPooledConnectionLifetime - Cached
IHttpClientFactory.CreateClient()results and typed clients injected into singletons - Duplicate typed-client registrations and shared implicit client names
- Stacked
AddStandardResilienceHandlerpipelines and unsafe-method retries - Undisposed responses/streams, sync-over-async, missing
CancellationToken - Unbounded HTTP fan-out and fragile named-client string literals
The package currently ships 19 documented diagnostics (HCR001–HCR085), with automatic code fixes for common lifetime, retry, disposal, cancellation, and registration problems.
Install
dotnet add package HttpClient.Resilience.Analyzers
For a library or shared project, keep the analyzer private to the project:
<PackageReference Include="HttpClient.Resilience.Analyzers" Version="0.1.142" PrivateAssets="all" />
Build normally with dotnet build. Diagnostics appear in supported IDEs, command-line builds, and CI without application configuration.
See it work
Product-flow diagrams from the real showcase sample (not stock screenshots):
30-second path
- Add the package reference with
PrivateAssets="all". - Run
dotnet build— no service registration or runtime setup required. - Fix or suppress high-confidence findings on critical outbound paths.
- Optionally copy a severity profile from the package
contentFiles(default,brownfield-adoption,strict-ci,library-author).
Feature snapshot
| Area | Examples |
|---|---|
HttpClient lifetime |
Per-request client creation, stale long-lived connections, cached factory clients |
| Dependency injection | Typed clients held by singletons, duplicate registrations, scoped state in handlers |
| Resilience and Polly | Duplicate handlers, unsafe HTTP method retries, per-request pipeline construction |
| Response ownership | Undisposed ResponseHeadersRead responses and HTTP content streams |
| Request correctness | Unchecked failure responses, shared default-header mutation, dropped cancellation tokens |
| Async and concurrency | Sync-over-async and obvious unbounded HTTP fan-out |
| Typed and named clients | Relative URLs without BaseAddress, duplicated string names, implicit-name collisions |
Configure severity
[*.cs]
dotnet_diagnostic.HCR041.severity = error
dotnet_diagnostic.HCR080.severity = suggestion
Compatibility
Targets Roslyn via a netstandard2.0 analyzer assembly. Works with modern .NET SDK builds, ASP.NET Core, and any project that uses HttpClient / IHttpClientFactory patterns the rules can prove statically. Heuristic checks use lower default severity; deliberate exceptions can be suppressed per rule.
Documentation
- Complete rule catalog
- Configuration guide
- Adoption guide
- Implementation status and limitations
- Source and releases
Licensed under the MIT License.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.142 | 0 | 7/26/2026 |
| 0.1.141 | 0 | 7/26/2026 |
| 0.1.140 | 44 | 7/23/2026 |
| 0.1.139 | 37 | 7/23/2026 |
| 0.1.138 | 28 | 7/23/2026 |
| 0.1.137 | 44 | 7/23/2026 |
| 0.1.136 | 39 | 7/23/2026 |
| 0.1.135 | 41 | 7/23/2026 |
| 0.1.134 | 37 | 7/23/2026 |
| 0.1.133 | 39 | 7/23/2026 |
| 0.1.132 | 44 | 7/23/2026 |
| 0.1.131 | 34 | 7/22/2026 |
| 0.1.130 | 40 | 7/22/2026 |
| 0.1.129 | 37 | 7/22/2026 |
| 0.1.128 | 36 | 7/22/2026 |
| 0.1.127 | 46 | 7/22/2026 |
| 0.1.126 | 43 | 7/22/2026 |
| 0.1.125 | 41 | 7/22/2026 |
| 0.1.124 | 35 | 7/22/2026 |
| 0.1.123 | 32 | 7/22/2026 |
Improve NuGet discoverability: keyword-rich Title/Description/PackageTags, conversion-funnel package README with product-flow visuals (absolute HTTPS image URLs), packed assets, and durable discoverability verification. Diagnostic IDs and severities are unchanged.