{"record":{"id":"6891db4bf310a8e9","repo":"App-vNext/Polly","slug":"value-cannot-be-null-6891db","errorCode":null,"errorMessage":"Value cannot be null.","messagePattern":"Value cannot be null\\.","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Retry/AsyncRetrySyntax.cs","lineNumber":64,"sourceCode":"    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onRetryAsync\"/> is <see langword=\"null\"/>.</exception>\n    public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, Func<Exception, int, Task> onRetryAsync) =>\n        policyBuilder.RetryAsync(1, onRetryAsync: (outcome, i, _) => onRetryAsync(outcome, i));\n\n    /// <summary>\n    ///     Builds an <see cref=\"AsyncRetryPolicy\" /> that will retry <paramref name=\"retryCount\" /> times\n    ///     calling <paramref name=\"onRetry\" /> on each retry with the raised exception and retry count.\n    /// </summary>\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 RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Action<Exception, int> onRetry)\n    {\n        if (onRetry == null)\n        {\n            throw new ArgumentNullException(nameof(onRetry));\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\" /> that will retry <paramref name=\"retryCount\" /> times\n    ///     calling <paramref name=\"onRetryAsync\" /> on each retry with the raised exception and retry count.\n    /// </summary>\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>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onRetryAsync\"/> is <see langword=\"null\"/>.</exception>\n    public static AsyncRetryPolicy RetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<Exception, int, Task> onRetryAsync)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Retry/AsyncRetrySyntax.cs#L46-L82","documentation":"Thrown by AsyncRetrySyntax.RetryAsync(this PolicyBuilder, retryCount, Action<Exception,int> onRetry) when onRetry is null. The callback is invoked on each retry, so a null callback would cause a NullReferenceException at retry time.","triggerScenarios":"Calling .RetryAsync(retryCount, onRetry: null) on a PolicyBuilder when wiring up the legacy async retry with a synchronous on-retry callback.","commonSituations":"Refactor that removed the logging callback but left the call site; optional callback passed as null where none of the no-callback overloads was chosen.","solutions":["Use the no-callback overload: policyBuilder.RetryAsync(retryCount) if you do not need an on-retry action.","Pass a real Action<Exception, int> (e.g. (ex, i) => logger.LogWarning(ex, \"retry {Count}\", i)).","Remove the callback argument entirely if it is unused."],"exampleFix":"// before\nvar policy = Policy.Handle<HttpRequestException>().RetryAsync(3, onRetry: null);\n// after\nvar policy = Policy.Handle<HttpRequestException>().RetryAsync(3);\n// or with a callback:\nvar policy = Policy.Handle<HttpRequestException>().RetryAsync(3, (ex, i) => logger.LogWarning(ex, \"retry {Count}\", i));","handlingStrategy":"validation","validationCode":"if (onRetry is null) throw new ArgumentException(\"onRetry callback is required; use the no-callback overload if none is needed.\");\nvar policy = builder.RetryAsync(retryCount, onRetry);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer the no-callback overload .RetryAsync(retryCount) when no on-retry action is needed.","Pass a logging callback by default for observability.","During refactors, remove the callback argument rather than nulling it."],"tags":["retry","argumentnull","async","callback","legacy"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}