{"record":{"id":"d901cfe992934d0c","repo":"App-vNext/Polly","slug":"value-cannot-be-null-parameter-onfallback","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'onFallback')","messagePattern":"Value cannot be null\\. \\(Parameter 'onFallback'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Polly/Fallback/FallbackSyntax.cs","lineNumber":133,"sourceCode":"    /// <summary>\n    /// Builds a <see cref=\"FallbackPolicy\"/> which provides a fallback action if the main execution fails.  Executes the main delegate, but if this throws a handled exception, first calls <paramref name=\"onFallback\"/> with details of the handled exception and the execution context; then calls <paramref name=\"fallbackAction\"/>.\n    /// </summary>\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 Fallback(this PolicyBuilder policyBuilder, Action<Exception, Context, CancellationToken> fallbackAction, Action<Exception, Context> 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 new FallbackPolicy(\n                policyBuilder,\n                onFallback,\n                fallbackAction);\n    }\n\n    private static void EmptyAction(Exception exception)\n    {\n        // No-op\n    }\n}\n\n/// <summary>\n/// Fluent API for defining a Fallback policy governing executions returning TResult.\n/// </summary>\npublic static class FallbackTResultSyntax","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Fallback/FallbackSyntax.cs#L115-L151","documentation":"ArgumentNullException thrown at construction by the non-generic Fallback syntax when onFallback is null. onFallback is the callback invoked before the fallback action runs; the builder requires a non-null delegate (use an empty lambda if you want no side effects).","triggerScenarios":"Calling Policy.Handle<...>().Fallback(fallbackAction, onFallback: null), or relying on a params overload where the second positional argument is null.","commonSituations":"Forgetting the second argument because another overload takes only one; passing null intending 'no callback' rather than an empty delegate; DI resolving the callback as null when the registration was missed.","solutions":["Pass a non-null onFallback delegate, e.g. _ => { } or (_, _) => { }.","If you want the simpler one-argument form, use the overload that supplies a default no-op callback.","Register/resolve the callback correctly from DI so it is never null."],"exampleFix":"// before\nvar policy = Policy\n    .Handle<HttpRequestException>()\n    .Fallback((ex, ctx, ct) => { }, onFallback: null);\n\n// after\nvar policy = Policy\n    .Handle<HttpRequestException>()\n    .Fallback((ex, ctx, ct) => { }, onFallback: (ex, ctx) => { });","handlingStrategy":"validation","validationCode":"if (onFallback is null) throw new ArgumentNullException(nameof(onFallback));\nvar policy = Policy.Handle<X>().Fallback(fallbackAction, onFallback);","typeGuard":"static bool IsValid(FallbackPolicy _) => true; // delegates are non-null when constructing via the fluent API","tryCatchPattern":"try { var p = builder.Fallback(action, onFallback); } catch (ArgumentNullException ex) when (ex.ParamName == \"onFallback\") { /* supply no-op */ throw; }","preventionTips":["Default optional callbacks to (_, _) => { } rather than null.","Use named arguments so fallbackAction and onFallback are unambiguous.","Register DI-resolved callbacks with a non-null fallback factory."],"tags":["fallback","argument-validation","null-check","csharp","legacy-api"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}