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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HttpClient.Resilience.Analyzers" Version="0.1.142">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HttpClient.Resilience.Analyzers" Version="0.1.142" />
                    
Directory.Packages.props
<PackageReference Include="HttpClient.Resilience.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add HttpClient.Resilience.Analyzers --version 0.1.142
                    
#r "nuget: HttpClient.Resilience.Analyzers, 0.1.142"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package HttpClient.Resilience.Analyzers@0.1.142
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=HttpClient.Resilience.Analyzers&version=0.1.142
                    
Install as a Cake Addin
#tool nuget:?package=HttpClient.Resilience.Analyzers&version=0.1.142
                    
Install as a Cake Tool

<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 without PooledConnectionLifetime
  • Cached IHttpClientFactory.CreateClient() results and typed clients injected into singletons
  • Duplicate typed-client registrations and shared implicit client names
  • Stacked AddStandardResilienceHandler pipelines 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 (HCR001HCR085), 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):

HttpClient analyzer build diagnostics HCR001 HCR002 HCR041 for IHttpClientFactory and resilience

Before and after code fix for HCR041 unsafe POST retries with AddStandardResilienceHandler

HttpClient.Resilience.Analyzers product loop from source code to IDE and CI profiles

30-second path

  1. Add the package reference with PrivateAssets="all".
  2. Run dotnet build — no service registration or runtime setup required.
  3. Fix or suppress high-confidence findings on critical outbound paths.
  4. 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

Licensed under the MIT License.

There are no supported framework assets in this package.

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
Loading failed

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.