{"record":{"id":"f4a85f3e332be266","repo":"App-vNext/Polly","slug":"onretry-f4a85f","errorCode":null,"errorMessage":"onRetry","messagePattern":"onRetry","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Retry/AsyncRetryTResultSyntax.cs","lineNumber":68,"sourceCode":"    public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<DelegateResult<TResult>, int, Task> onRetryAsync) =>\n        policyBuilder.RetryAsync(1, onRetryAsync: (outcome, i, _) => onRetryAsync(outcome, i));\n\n    /// <summary>\n    ///     Builds an <see cref=\"AsyncRetryPolicy{TResult}\" /> that will retry <paramref name=\"retryCount\" /> times\n    ///     calling <paramref name=\"onRetry\" /> on each retry with the handled exception or result and retry count.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"retryCount\">The retry count.</param>\n    /// <param name=\"onRetry\">The action to call on each retry.</param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">retryCount;Value must be greater than or equal to zero.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onRetry\"/> is <see langword=\"null\"/>.</exception>\n    public static AsyncRetryPolicy<TResult> RetryAsync<TResult>(this PolicyBuilder<TResult> policyBuilder, int retryCount, Action<DelegateResult<TResult>, int> onRetry)\n    {\n        if (onRetry == null)\n        {\n            throw new ArgumentNullException(nameof(onRetry));\n        }\n\n#pragma warning disable 1998 // async method has no awaits, will run synchronously\n        return policyBuilder.RetryAsync(retryCount,\n            onRetryAsync: async (outcome, i, _) => onRetry(outcome, i));\n#pragma warning restore 1998\n    }\n\n    /// <summary>\n    ///     Builds an <see cref=\"AsyncRetryPolicy{TResult}\" /> that will retry <paramref name=\"retryCount\" /> times\n    ///     calling <paramref name=\"onRetryAsync\" /> on each retry with the handled exception or result and retry count.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"retryCount\">The retry count.</param>\n    /// <param name=\"onRetryAsync\">The action to call asynchronously on each retry.</param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">retryCount;Value must be greater than or equal to zero.</exception>","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Retry/AsyncRetryTResultSyntax.cs#L50-L86","documentation":"Thrown by RetryAsync<TResult> (result-typed retry policy) when the synchronous Action<DelegateResult<TResult>, int> onRetry callback is null. This overload wraps the Action into an async delegate, but still null-checks the Action first; the callback surfaces the handled result/exception and retry count on each retry. Construction fails eagerly because a null callback cannot run.","triggerScenarios":"Calling RetryAsync<TResult>(retryCount, onRetry: null) on a PolicyBuilder<TResult>, or passing an optional Action that defaulted to null.","commonSituations":"Building a result-typed retry (e.g. for handling HttpResponseMessage with bad status codes) and forgetting the logging hook, or wiring through a wrapper that forwards an unset parameter.","solutions":["Provide a non-null Action<DelegateResult<TResult>, int>, e.g. (outcome, i) => Log(outcome, i).","Default optional callbacks in your wrapper to a no-op.","Use the overload without onRetry if you need no per-retry side-effect."],"exampleFix":"// before\nPolicy.HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)\n    .RetryAsync(3, onRetry: null);\n// after\nPolicy.HandleResult<HttpResponseMessage>(r => !r.IsSuccessStatusCode)\n    .RetryAsync(3, onRetry: (outcome, i) => Log.Retry(outcome, i));","handlingStrategy":"validation","validationCode":"if (onRetry is null) throw new InvalidOperationException(\"onRetry callback required.\");\n// then call RetryAsync<TResult>(retryCount, onRetry)","typeGuard":"static bool IsValidOnRetry(Action<DelegateResult<TResult>, int> a) => a is not null;","tryCatchPattern":"try { policy = Policy.HandleResult<T>(IsHandled).RetryAsync(retryCount, onRetry); }\ncatch (ArgumentNullException ex) when (ex.ParamName == nameof(onRetry))\n{ /* log config error, use no-op callback */ }","preventionTips":["Default optional Action parameters to a no-op in wrapper methods.","Build result-typed policies in a single factory to centralize callback wiring.","Enable NRTs so the compiler flags null Action assignments."],"tags":["polly","retry","argument-null","callback","result-typed","legacy"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}