{"record":{"id":"64c8f46c47761ccb","repo":"App-vNext/Polly","slug":"value-cannot-be-null-parameter-action-64c8f4","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'action')","messagePattern":"Value cannot be null\\. \\(Parameter 'action'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/NoOp/NoOpPolicy.cs","lineNumber":19,"sourceCode":"﻿#nullable enable\nnamespace Polly.NoOp;\n\n/// <summary>\n/// A no op policy that can be applied to delegates.\n/// </summary>\npublic class NoOpPolicy : Policy, INoOpPolicy\n{\n    internal NoOpPolicy()\n    {\n    }\n\n    /// <inheritdoc/>\n    [DebuggerStepThrough]\n    protected override TResult Implementation<TResult>(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)\n    {\n        if (action is null)\n        {\n            throw new ArgumentNullException(nameof(action));\n        }\n\n        return NoOpEngine.Implementation(action, context, cancellationToken);\n    }\n}\n\n/// <summary>\n/// A no op policy that can be applied to delegates returning a value of type <typeparamref name=\"TResult\" />.\n/// </summary>\n/// <typeparam name=\"TResult\">The type of return values this policy will handle.</typeparam>\npublic class NoOpPolicy<TResult> : Policy<TResult>, INoOpPolicy<TResult>\n{\n    internal NoOpPolicy()\n    {\n    }\n\n    /// <inheritdoc/>\n    [DebuggerStepThrough]","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/NoOp/NoOpPolicy.cs#L1-L37","documentation":"ArgumentNullException thrown by the synchronous NoOpPolicy.Implementation when the action delegate is null. NoOp invokes the delegate directly via NoOpEngine.Implementation, so a null func is rejected at the Execute boundary with parameter name 'action'.","triggerScenarios":"Calling Policy.NoOp().Execute(null) or passing a null Func<Context, CancellationToken, TResult>.","commonSituations":"Null delegate from a factory/DI; refactor removing the action without updating the call site; test scaffolding that left the action unset.","solutions":["Pass a non-null synchronous delegate to Execute.","Coalesce the delegate: action ?? ((_, _) => default).","Confirm the DI/factory registration returns a concrete delegate."],"exampleFix":"// before\nvar policy = Policy.NoOp();\nvar v = policy.Execute(_action /* null */, ct);\n\n// after\nvar policy = Policy.NoOp();\nFunc<Context, CancellationToken, int> action = _action ?? ((_, _) => 0);\nvar v = policy.Execute(action, ct);","handlingStrategy":"validation","validationCode":"if (action is null) throw new ArgumentNullException(nameof(action));\nvar v = Policy.NoOp().Execute(action, ctx, ct);","typeGuard":"static Func<Context, CancellationToken, T> EnsureAction<T>(Func<Context, CancellationToken, T> a) => a ?? ((_, _) => default);","tryCatchPattern":"try { return noOpPolicy.Execute(action, ct); } catch (ArgumentNullException ex) when (ex.ParamName == \"action\") { /* supply delegate */ throw; }","preventionTips":["Validate synchronous delegates from DI/factories are non-null.","Coalesce null actions with a default-returning delegate.","Keep a unit test that runs NoOp synchronously with a real delegate."],"tags":["noop","argument-validation","null-check","sync","csharp","legacy-api"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}