{"record":{"id":"ce149d396fefec91","repo":"App-vNext/Polly","slug":"timeoutprovider-ce149d","errorCode":null,"errorMessage":"timeoutProvider","messagePattern":"timeoutProvider","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs","lineNumber":220,"sourceCode":"        {\n            throw new ArgumentOutOfRangeException(nameof(timeout));\n        }\n\n        return TimeoutAsync<TResult>(_ => timeout, timeoutStrategy, onTimeoutAsync);\n    }\n\n    /// <summary>\n    /// Builds an <see cref=\"AsyncPolicy{TResult}\"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref=\"TimeoutRejectedException\"/> will be thrown if the delegate does not complete within the configured timeout.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"timeoutProvider\">A function to provide the timeout for this execution.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"timeoutProvider\"/> is <see langword=\"null\"/>.</exception>\n    /// <returns>The policy instance.</returns>\n    public static AsyncTimeoutPolicy<TResult> TimeoutAsync<TResult>(Func<TimeSpan> timeoutProvider)\n    {\n        if (timeoutProvider == null)\n        {\n            throw new ArgumentNullException(nameof(timeoutProvider));\n        }\n\n        return TimeoutAsync<TResult>(_ => timeoutProvider(), TimeoutStrategy.Optimistic, EmptyHandlerOfT<TResult>);\n    }\n\n    /// <summary>\n    /// Builds an <see cref=\"AsyncPolicy{TResult}\"/> that will wait asynchronously for a delegate to complete for a specified period of time. A <see cref=\"TimeoutRejectedException\"/> will be thrown if the delegate does not complete within the configured timeout.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"timeoutProvider\">A function to provide the timeout for this execution.</param>\n    /// <param name=\"timeoutStrategy\">The timeout strategy.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"timeoutProvider\"/> is <see langword=\"null\"/>.</exception>\n    /// <returns>The policy instance.</returns>\n    public static AsyncTimeoutPolicy<TResult> TimeoutAsync<TResult>(Func<TimeSpan> timeoutProvider, TimeoutStrategy timeoutStrategy)\n    {\n        if (timeoutProvider == null)\n        {\n            throw new ArgumentNullException(nameof(timeoutProvider));","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Timeout/AsyncTimeoutTResultSyntax.cs#L202-L238","documentation":"Thrown by the parameterless-callback overload TimeoutAsync<TResult>(Func<TimeSpan> timeoutProvider) when the provider is null. This overload wires a default empty handler and forces Optimistic strategy, so the only thing it validates is the provider itself. Construction-time guard.","triggerScenarios":"Calling Policy.TimeoutAsync<TResult>(null) or with a provider variable that is null. Reached when a simpler 'no callback' usage is wanted but the provider was never assigned.","commonSituations":"DI returning null for a configured provider; refactoring a fixed timeout into a provider and forgetting the assignment; optional parameter defaulting to null.","solutions":["Pass a non-null Func<TimeSpan>, e.g. () => TimeSpan.FromSeconds(30).","If the timeout is static, prefer TimeoutAsync<TResult>(TimeSpan) which takes the value directly.","Default the provider before the call: provider ?? (() => TimeSpan.FromSeconds(30))."],"exampleFix":"// before\nFunc<TimeSpan> provider = null;\nPolicy.TimeoutAsync<MyResult>(provider);\n\n// after\nFunc<TimeSpan> provider = () => TimeSpan.FromSeconds(30);\nPolicy.TimeoutAsync<MyResult>(provider);","handlingStrategy":"validation","validationCode":"timeoutProvider ??= () => TimeSpan.FromSeconds(30);\nvar policy = Policy.TimeoutAsync<TResult>(timeoutProvider);","typeGuard":"static bool HasProvider(Func<TimeSpan> p) => p is not null;","tryCatchPattern":null,"preventionTips":["Default the provider when it comes from optional config.","Use the TimeSpan overload for static timeouts.","Enable nullable reference types."],"tags":["argument-null","validation","timeout","legacy-api","polly-v7"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}