{"record":{"id":"6d5e2eff0ac2025d","repo":"App-vNext/Polly","slug":"sleepdurations-6d5e2e","errorCode":null,"errorMessage":"sleepDurations","messagePattern":"sleepDurations","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Retry/RetrySyntax.cs","lineNumber":453,"sourceCode":"\n        return policyBuilder.WaitAndRetry(sleepDurations, (outcome, span, _, ctx) => onRetry(outcome, span, ctx));\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"Policy\"/> that will wait and retry as many times as there are provided <paramref name=\"sleepDurations\"/>\n    /// calling <paramref name=\"onRetry\"/> on each retry with the raised exception, current sleep duration, retry count and context data.\n    /// On each retry, the duration to wait is the current <paramref name=\"sleepDurations\"/> item.\n    /// </summary>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"sleepDurations\">The sleep durations to wait for on each retry.</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=\"sleepDurations\"/> or <paramref name=\"onRetry\"/> is <see langword=\"null\"/>.</exception>\n    public static RetryPolicy WaitAndRetry(this PolicyBuilder policyBuilder, IEnumerable<TimeSpan> sleepDurations, Action<Exception, TimeSpan, int, Context> onRetry)\n    {\n        if (sleepDurations == null)\n        {\n            throw new ArgumentNullException(nameof(sleepDurations));\n        }\n\n        if (onRetry == null)\n        {\n            throw new ArgumentNullException(nameof(onRetry));\n        }\n\n        return new RetryPolicy(\n            policyBuilder,\n            onRetry,\n            sleepDurationsEnumerable: sleepDurations);\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"Policy\"/> that will wait and retry indefinitely until the action succeeds.\n    ///     On each retry, the duration to wait is calculated by calling <paramref name=\"sleepDurationProvider\" /> with\n    ///     the current retry number (1 for first retry, 2 for second etc).\n    /// </summary>","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Retry/RetrySyntax.cs#L435-L471","documentation":"This WaitAndRetry overload (RetrySyntax.cs:453) takes an IEnumerable<TimeSpan> sleepDurations and throws ArgumentNullException when that collection is null. The collection defines both the per-attempt wait and the retry count (one attempt per element), so a null collection gives Polly no retry plan.","triggerScenarios":"Calling Policy.Handle<...>().WaitAndRetry(null, onRetry) — passing null for the IEnumerable<TimeSpan> sleepDurations.","commonSituations":"A collection builder returned null; a config section that maps to a TimeSpan array was empty/unmapped and deserialized to null; conditional initialization that never assigned the list.","solutions":["Pass a non-null IEnumerable<TimeSpan>, e.g. an array of wait durations.","If the list is built dynamically, default to Enumerable.Empty<TimeSpan>() or a sensible fallback array rather than null.","Verify config binding produced a populated collection."],"exampleFix":"// before\nTimeSpan[] durations = config.GetSection(\"Durations\").Get<TimeSpan[]>();\nvar policy = Policy.Handle<X>().WaitAndRetry(durations, onRetry); // durations may be null\n// after\nvar durations = config.GetSection(\"Durations\").Get<TimeSpan[]>() ?? Array.Empty<TimeSpan>();\nvar policy = Policy.Handle<X>().WaitAndRetry(durations, onRetry);","handlingStrategy":"validation","validationCode":"durations ??= Array.Empty<TimeSpan>();\nif (durations is null) throw new ArgumentNullException(nameof(durations));\nvar policy = Policy.Handle<X>().WaitAndRetry(durations, onRetry);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Coalesce config-bound collections with ?? Array.Empty<TimeSpan>() or a default array.","Enable nullable reference types so a null IEnumerable is a compile-time warning.","Validate config binding produced elements, not just a non-null reference."],"tags":["polly","retry","argument-validation","nullable","collection","configuration","csharp"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}