ZeroAlloc.Resilience 3.3.5

dotnet add package ZeroAlloc.Resilience --version 3.3.5
                    
NuGet\Install-Package ZeroAlloc.Resilience -Version 3.3.5
                    
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="ZeroAlloc.Resilience" Version="3.3.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Resilience" Version="3.3.5" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Resilience" />
                    
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 ZeroAlloc.Resilience --version 3.3.5
                    
#r "nuget: ZeroAlloc.Resilience, 3.3.5"
                    
#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 ZeroAlloc.Resilience@3.3.5
                    
#: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=ZeroAlloc.Resilience&version=3.3.5
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Resilience&version=3.3.5
                    
Install as a Cake Tool

ZeroAlloc.Resilience

NuGet Build License: MIT AOT GitHub Sponsors

Retry, timeout, rate limiting and circuit breaking for .NET, declared as attributes on an interface and compiled into a proxy: a source-generated alternative to Polly with no allocation on the happy path.

Why ZeroAlloc.Resilience

  • 0 B per successful call through [Retry] and [CircuitBreaker], asserted by tests on every run. Polly v8 allocates a 64 B ResilienceContext per call.
  • 14.7× and 15.0× faster than Polly v8 on the retry and circuit-breaker happy paths, and 5.9× faster with all four policies stacked, measured in the same run.
  • Works under NativeAOT and trimming. The proxy is plain generated code with no reflection, published as a NativeAOT app in CI.
  • Mistakes surface at compile time. A misspelled fallback, an invalid attribute value or a timeout on a method without a CancellationToken is a compiler diagnostic.

Install

dotnet add package ZeroAlloc.Resilience

Quick start

using Microsoft.Extensions.DependencyInjection;
using ZeroAlloc.Resilience;

var services = new ServiceCollection();
services.AddWeatherClientResilience<FlakyWeatherClient>(); // generated: registers the proxy

var client = services.BuildServiceProvider().GetRequiredService<IWeatherClient>();
Console.WriteLine(await client.GetForecastAsync("Amsterdam", CancellationToken.None));
// Amsterdam: sunny, after 3 attempts

[Retry(MaxAttempts = 3, BackoffMs = 100, Jitter = true)]
[Timeout(Ms = 5_000)]
[CircuitBreaker(MaxFailures = 5, ResetMs = 30_000)]
public interface IWeatherClient
{
    ValueTask<string> GetForecastAsync(string city, CancellationToken ct);
}

public sealed class FlakyWeatherClient : IWeatherClient
{
    private int _calls;

    public ValueTask<string> GetForecastAsync(string city, CancellationToken ct)
        => ++_calls < 3
            ? throw new HttpRequestException($"attempt {_calls} failed")
            : ValueTask.FromResult($"{city}: sunny, after {_calls} attempts");
}

The first two calls throw, the proxy retries, and the caller only sees the result. Callers inject IWeatherClient as usual.

What you get

  • Retry with exponential backoff, jitter, a per-attempt timeout and a cap on the delay.
  • Timeout over the whole operation, retries and backoff included.
  • Rate limiting with a lock-free token bucket, shared per interface or per proxy.
  • Circuit breaker with half-open probing and an optional fallback method.
  • A fixed, predictable order: rate limit, circuit breaker, timeout, retry, whatever order you write the attributes in.
  • Exceptions or Results: return a ZeroAlloc.Results Result<T> and policy failures come back as a failure instead of a throw.
  • Result-aware retry: retry only the failures you call transient, and honour Retry-After hints.
  • Per-method overrides of the interface-level policies, for example one attempt for a non-idempotent POST.
  • One-line DI registration through a generated Add{Service}Resilience<TImpl>() extension.
  • Compile-time diagnostics ZR0001–ZR0013: the full list. Every attribute property: attribute reference.

Performance

Against Polly.Core 8.8.0 on .NET 10.0.13, measured 2026-10-15. Allocations are exact; speed is a same-run ratio, because the benchmark host is a shared VM.

Operation ZA vs Polly Polly alloc ZA alloc
Retry, happy path 14.7× faster 64 B 0 B
CircuitBreaker, closed 15.0× faster 64 B 0 B
All-policies stacked, happy path 5.9× faster 104 B 144 B

With all policies stacked, the 144 B is the linked CancellationTokenSource and timer that [Timeout] needs; without [Timeout] the proxy allocates nothing. Polly walks a delegate chain per call; ZA emits one method with the policy checks inline. Failure paths, an open circuit and the full method: docs/performance.md.

Learn more

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on ZeroAlloc.Resilience:

Package Downloads
ZeroAlloc.Scheduling

Source-generated zero-allocation background job scheduling for .NET.

ZeroAlloc.Outbox

Source-generated transactional outbox for .NET.

ZeroAlloc.Rest.Resilience

Wires ZeroAlloc.Rest clients through ZeroAlloc.Resilience proxies. Annotate a [ZeroAllocRestClient] interface with [Retry]/[Timeout]/[CircuitBreaker]; call AddRestResilience to register the resilience-wrapped HTTP client.

ZeroAlloc.Scheduling.Resilience

ZeroAlloc.Resilience bridge for ZeroAlloc.Scheduling — wraps IJobTypeExecutor implementations in a Resilience-generated proxy.

AI.Sentinel

Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.3.5 5,488 10/16/2026
3.3.4 2,464 10/15/2026
3.3.3 4,501 10/12/2026
3.3.2 4,702 10/11/2026
3.3.1 13,776 9/30/2026
3.3.0 8,595 9/27/2026
3.2.0 2,616 9/26/2026
3.1.0 3,517 9/25/2026
3.0.0 111 9/25/2026
2.0.1 938 9/25/2026
2.0.0 661 9/24/2026
1.3.8 123 9/24/2026
1.3.7 106 9/24/2026
1.3.6 147 9/24/2026
1.3.5 109 9/24/2026
1.3.4 1,454 9/20/2026
1.3.3 238 9/20/2026
1.3.2 5,864 9/19/2026
1.3.1 3,646 8/12/2026
1.3.0 6,164 5/13/2026
Loading failed