DotNetExtras.Retry 1.0.1

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

DotNetExtras.Retry

DotNetExtras.Retry is a .NET Core library that allows applications to recover from and retry failed operations. This library is similar to Polly, but it is much simpler because it only focuses only on three most common scenarios.

Use the DotNetExtras.Retry library to:

  1. Retry an operation a specified number of times with an optional delay between attempts.
  2. Retry an operation for the specified period of time with an optional delay between attempts.
  3. Reload an object (configuration, settings, etc.) and retry an operation with the reloaded state (one or more times or for a period of time, with an optional delay between attempts).

The nice thing about the DotNetExtras.Retry library is that it is extremely easy to integrate with the existing code.

Usage

The following example illustrates how to detect a failure that may be caused by an old configuration setting, reload the settings, and retry the operation.

using DotNetExtras.Retry;
...

// This class implements the Reload() method of the IReloadable interface,
// in which it reloads the configuration settings that could have changed.
ReloadableService service = new();

// If the operation throws a NotSupportedException,
// reload the service object and retry the operation one more time.
// The operation is expected to return an int value.
int result = Execute.WithRetry<NotSupportedException, int>(() => 
{
    // BEGINNING OF THE CODE BLOCK THAT WILL BE RETRIED.
    try
    {
        // Attempt to perform the operation.
        return service.DoSomething();
    }
    // This is not the expected exception for the retry,
    // but...
    catch (InvalidOperationException ex)
    {
        // ...we can simulate the expected exception for an appropriate condition.
        if (ex.Message.StartsWith("Unexpected"))
        {
            throw new NotSupportedException("Simulated exception triggering a reload.", ex);
        }

        // This will handle both the expected exception 
        // leading to a reload and retry (one retry attempt only),
        // as well as an unhandled exception that will 
        // result in error.
        throw;
    }
    // END OF THE CODE BLOCK THAT WILL BE RETRIED.

}, service);
// We are passing the same service object here because it is the one that 
// implements the reload method, but it can be a different object.
// We use the defaults for the delay (no delay) and the maximum attempts (2).

You can find the complete example and other scenarios covered in the demo application.

Documentation

For complete documentation, usage details, and code samples, see:

Package

Install the latest version of the DotNetExtras.Retry NuGet package from:

See also

Check out other DotNetExtras libraries at:

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 was computed.  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 was computed.  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

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
1.0.1 65 8/15/2025
1.0.0 113 8/11/2025

Improved documentation, no functional changes.