{"record":{"id":"5757f8b6c7c65b94","repo":"App-vNext/Polly","slug":"onretry-5757f8","errorCode":null,"errorMessage":"onRetry","messagePattern":"onRetry","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Retry/RetryTResultSyntax.cs","lineNumber":59,"sourceCode":"    /// 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 RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> policyBuilder, int retryCount, Action<DelegateResult<TResult>, int> onRetry)\n    {\n        if (retryCount < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(retryCount), \"Value must be greater than or equal to zero.\");\n        }\n\n        if (onRetry == null)\n        {\n            throw new ArgumentNullException(nameof(onRetry));\n        }\n\n        return policyBuilder.Retry(retryCount, (outcome, i, _) => onRetry(outcome, i));\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"Policy{TResult}\"/> that will retry once\n    /// calling <paramref name=\"onRetry\"/> on retry with the handled exception or result, retry count and context data.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"onRetry\">The action to call on each retry.</param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onRetry\"/> is <see langword=\"null\"/>.</exception>\n    public static RetryPolicy<TResult> Retry<TResult>(this PolicyBuilder<TResult> policyBuilder, Action<DelegateResult<TResult>, int, Context> onRetry) =>\n        policyBuilder.Retry(1, onRetry);\n\n    /// <summary>","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Retry/RetryTResultSyntax.cs#L41-L77","documentation":"This generic Retry<TResult> overload (RetryTResultSyntax.cs:59) throws ArgumentNullException when onRetry is null. The callback Action<DelegateResult<TResult>, int> reports each retry's handled result/exception and attempt number; it is mandatory.","triggerScenarios":"Calling Policy.HandleResult<T>(...).Retry(retryCount, null) with onRetry typed Action<DelegateResult<TResult>, int>.","commonSituations":"Removed logging; field null; overload-resolution confusion with the Context-bearing variant.","solutions":["Pass a non-null Action<DelegateResult<TResult>, int>.","If no callback is wanted, use the Retry(int) overload that omits onRetry."],"exampleFix":"// before\nvar policy = Policy.HandleResult<int>(r => r < 0).Retry(3, null);\n// after\nvar policy = Policy.HandleResult<int>(r => r < 0).Retry(3, (outcome, attempt) => log.LogWarning(\"retry {Attempt}\", attempt));","handlingStrategy":"validation","validationCode":"if (onRetry is null) throw new ArgumentNullException(nameof(onRetry));\nvar policy = Policy.HandleResult<int>(r => r < 0).Retry(3, onRetry);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable nullable reference types.","If no callback is needed, use the Retry(int) overload that omits onRetry.","Centralize policy construction in a factory to avoid null callbacks."],"tags":["polly","retry","argument-validation","nullable","callback","generic","csharp"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}