HttpClient.Resilience.Analyzers
0.1.162
See the version list below for details.
dotnet add package HttpClient.Resilience.Analyzers --version 0.1.162
NuGet\Install-Package HttpClient.Resilience.Analyzers -Version 0.1.162
<PackageReference Include="HttpClient.Resilience.Analyzers" Version="0.1.162"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="HttpClient.Resilience.Analyzers" Version="0.1.162" />
<PackageReference Include="HttpClient.Resilience.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add HttpClient.Resilience.Analyzers --version 0.1.162
#r "nuget: HttpClient.Resilience.Analyzers, 0.1.162"
#:package HttpClient.Resilience.Analyzers@0.1.162
#addin nuget:?package=HttpClient.Resilience.Analyzers&version=0.1.162
#tool nuget:?package=HttpClient.Resilience.Analyzers&version=0.1.162
<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, unsafe-method retries, unsafe-method hedging, and customAddResilienceHandlerpipelines that retry unsafe methods - Undisposed responses/streams, sync-over-async, missing
CancellationToken - Unbounded HTTP fan-out and fragile named-client string literals
The package currently ships 21 documented diagnostics (HCR001–HCR085), with automatic code fixes for common lifetime, retry, hedging, 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.162" 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):
Quick start
- 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, concurrent hedging of unsafe methods, custom pipelines retrying unsafe methods, 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
- Documentation site
- Getting started
- Complete rule catalog
- Configuration guide
- Adoption guide
- FAQ
- 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.163 | 53 | 8/13/2026 |
| 0.1.162 | 44 | 8/13/2026 |
| 0.1.161 | 42 | 8/12/2026 |
| 0.1.160 | 66 | 8/12/2026 |
| 0.1.159 | 104 | 8/3/2026 |
| 0.1.158 | 97 | 8/3/2026 |
| 0.1.157 | 103 | 8/3/2026 |
| 0.1.156 | 94 | 8/3/2026 |
| 0.1.155 | 91 | 8/3/2026 |
| 0.1.154 | 99 | 8/3/2026 |
| 0.1.153 | 99 | 8/3/2026 |
| 0.1.152 | 95 | 8/3/2026 |
| 0.1.151 | 96 | 8/3/2026 |
| 0.1.150 | 87 | 8/3/2026 |
| 0.1.149 | 86 | 8/3/2026 |
| 0.1.148 | 86 | 8/3/2026 |
| 0.1.147 | 86 | 8/3/2026 |
| 0.1.146 | 94 | 8/3/2026 |
| 0.1.145 | 92 | 8/3/2026 |
| 0.1.144 | 100 | 8/3/2026 |
Add HCR043 to warn when custom AddResilienceHandler pipelines call AddRetry while the typed or named client sends POST/PUT/PATCH/DELETE/CONNECT. Conservative code fix disables unsafe-method retries for HttpRetryStrategyOptions object creation.