{"record":{"id":"bf190992997da685","repo":"App-vNext/Polly","slug":"value-cannot-be-null-parameter-fallbackaction","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'fallbackAction')","messagePattern":"Value cannot be null\\. \\(Parameter 'fallbackAction'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Fallback/FallbackSyntax.cs","lineNumber":218,"sourceCode":"\n        return policyBuilder.Fallback((_, _, _) => fallbackValue, (outcome, _) => onFallback(outcome));\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"FallbackPolicy\"/> which provides a fallback value if the main execution fails.  Executes the main delegate, but if this throws a handled exception or raises a handled result, first calls <paramref name=\"onFallback\"/> with details of the handled exception or result; then calls <paramref name=\"fallbackAction\"/> and returns its result.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"fallbackAction\">The fallback action.</param>\n    /// <param name=\"onFallback\">The action to call before invoking the fallback delegate.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"fallbackAction\"/> is <see langword=\"null\"/>.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onFallback\"/> is <see langword=\"null\"/>.</exception>\n    /// <returns>The policy instance.</returns>\n    public static FallbackPolicy<TResult> Fallback<TResult>(this PolicyBuilder<TResult> policyBuilder, Func<TResult> fallbackAction, Action<DelegateResult<TResult>> onFallback)\n    {\n        if (fallbackAction == null)\n        {\n            throw new ArgumentNullException(nameof(fallbackAction));\n        }\n\n        if (onFallback == null)\n        {\n            throw new ArgumentNullException(nameof(onFallback));\n        }\n\n        return policyBuilder.Fallback((_, _, _) => fallbackAction(), (outcome, _) => onFallback(outcome));\n    }\n\n    /// <summary>\n    /// Builds a <see cref=\"FallbackPolicy\"/> which provides a fallback value if the main execution fails.  Executes the main delegate, but if this throws a handled exception or raises a handled result, first calls <paramref name=\"onFallback\"/> with details of the handled exception or result; then calls <paramref name=\"fallbackAction\"/> and returns its result.\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"policyBuilder\">The policy builder.</param>\n    /// <param name=\"fallbackAction\">The fallback action.</param>\n    /// <param name=\"onFallback\">The action to call before invoking the fallback delegate.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"fallbackAction\"/> is <see langword=\"null\"/>.</exception>","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Fallback/FallbackSyntax.cs#L200-L236","documentation":"ArgumentNullException thrown by Fallback<TResult>(PolicyBuilder<TResult>, Func<TResult> fallbackAction, Action<DelegateResult<TResult>> onFallback) when fallbackAction is null. The fallback value producer is required; without it the policy cannot supply a substitute result.","triggerScenarios":"Calling Policy<TResult>.Handle<...>().Fallback(fallbackAction: null, onFallback).","commonSituations":"Injecting the fallback factory from DI where the registration is missing; conditional initialization that left the field null.","solutions":["Supply a non-null Func<TResult>.","Validate the DI registration for the fallback factory before building the policy.","Default to a value-returning lambda: () => default if a real producer is unavailable."],"exampleFix":"// before\nvar policy = Policy<int>\n    .Handle<HttpRequestException>()\n    .Fallback(fallbackAction: null, onFallback: _ => { });\n\n// after\nvar policy = Policy<int>\n    .Handle<HttpRequestException>()\n    .Fallback(fallbackAction: () => cache.GetCached(), onFallback: _ => { });","handlingStrategy":"validation","validationCode":"if (fallbackAction is null) throw new ArgumentNullException(nameof(fallbackAction));\nvar policy = Policy<TResult>.Handle<X>().Fallback(fallbackAction, onFallback);","typeGuard":"static Func<T> EnsureProducer<T>(Func<T> p) => p ?? (() => default);","tryCatchPattern":"try { var p = builder.Fallback(fallbackAction, onFallback); } catch (ArgumentNullException ex) when (ex.ParamName == \"fallbackAction\") { /* register producer */ throw; }","preventionTips":["Register the fallback producer in DI and validate it resolves non-null at startup.","Default the producer to () => default when no real value exists.","Add a smoke test that constructs the policy with the resolved producer."],"tags":["fallback","argument-validation","null-check","generics","csharp","legacy-api"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}