{"record":{"id":"9fff3ca9eeaef3d5","repo":"App-vNext/Polly","slug":"action","errorCode":null,"errorMessage":"action","messagePattern":"action","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Timeout/AsyncTimeoutPolicy.cs","lineNumber":32,"sourceCode":"        TimeoutStrategy timeoutStrategy,\n        Func<Context, TimeSpan, Task, Exception, Task> onTimeoutAsync)\n    {\n        _timeoutProvider = timeoutProvider;\n        _timeoutStrategy = timeoutStrategy;\n        _onTimeoutAsync = onTimeoutAsync;\n    }\n\n    /// <inheritdoc/>\n    [DebuggerStepThrough]\n    protected override Task<TResult> ImplementationAsync<TResult>(\n        Func<Context, CancellationToken, Task<TResult>> action,\n        Context context,\n        CancellationToken cancellationToken,\n        bool continueOnCapturedContext)\n    {\n        if (action is null)\n        {\n            throw new ArgumentNullException(nameof(action));\n        }\n\n        return AsyncTimeoutEngine.ImplementationAsync(\n            action,\n            context,\n            _timeoutProvider,\n            _timeoutStrategy,\n            _onTimeoutAsync,\n            continueOnCapturedContext,\n            cancellationToken);\n    }\n}\n\n/// <summary>\n/// A timeout policy which can be applied to async delegates.\n/// </summary>\n/// <typeparam name=\"TResult\">The return type of delegates which may be executed through the policy.</typeparam>\npublic class AsyncTimeoutPolicy<TResult> : AsyncPolicy<TResult>, ITimeoutPolicy<TResult>","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Timeout/AsyncTimeoutPolicy.cs#L14-L50","documentation":"ArgumentNullException (ParamName \"action\") is thrown by the non-generic AsyncTimeoutPolicy.ImplementationAsync (AsyncTimeoutPolicy.cs:30-33) when the delegate passed for execution is null. This is the protected execution entry point; the null check protects the engine before it dereferences the action to start the task. It indicates the caller handed the policy a null lambda rather than a real operation.","triggerScenarios":"Calling policy.ExecuteAsync(null) or ExecuteAsync((Func<...>)null) on an AsyncTimeoutPolicy; passing a null Func<Context,CancellationToken,Task<TResult>> directly through the lower-level ImplementationAsync surface.","commonSituations":"Refactor that extracted the operation into a variable that resolved to null; DI failing to resolve the delegate factory; tests stubbing the action parameter; conditional code paths that forget to assign the action.","solutions":["Pass a non-null delegate: policy.ExecuteAsync(ct => DoWorkAsync(ct)).","Guard the action variable before execution: if (action is null) throw new InvalidOperationException(...).","Ensure DI registrations for the delegate factory return a real delegate, never null."],"exampleFix":"// before\nFunc<CancellationToken, Task<string>> action = GetAction(); // returns null\nawait timeoutPolicy.ExecuteAsync(action);\n\n// after\nFunc<CancellationToken, Task<string>> action = GetAction()\n    ?? throw new InvalidOperationException(\"action factory returned null\");\nawait timeoutPolicy.ExecuteAsync(action);","handlingStrategy":"validation","validationCode":"if (action is null) throw new InvalidOperationException(\"Execution action must be provided.\");\nawait timeoutPolicy.ExecuteAsync(action);","typeGuard":"static bool IsValidAction<TResult>(Func<Context, CancellationToken, Task<TResult>> action)\n    => action is not null;","tryCatchPattern":null,"preventionTips":["Always pass an inline lambda or a verified non-null delegate to ExecuteAsync; avoid nullable delegate variables.","Coalesce null with ?? throw new InvalidOperationException(...) at the source so the error is contextual.","Validate DI-resolved delegate factories in the composition root."],"tags":["argumentnullexception","timeout","execution","validation","polly"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}