{"record":{"id":"5bafdb50bf8abd6f","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-zero-5bafdb","errorCode":null,"errorMessage":"Value must be greater than zero.","messagePattern":"Value must be greater than zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/Bulkhead/BulkheadTResultSyntax.cs","lineNumber":59,"sourceCode":"        => Bulkhead<TResult>(maxParallelization, maxQueuingActions, EmptyAction);\n\n    /// <summary>\n    /// Builds a bulkhead isolation <see cref=\"Policy{TResult}\" />, which limits the maximum concurrency of actions executed through the policy.  Imposing a maximum concurrency limits the potential of governed actions, when faulting, to bring down the system.\n    /// <para>When an execution would cause the number of actions executing concurrently through the policy to exceed <paramref name=\"maxParallelization\" />, the policy allows a further <paramref name=\"maxQueuingActions\" /> executions to queue, waiting for a concurrent execution slot.  When an execution would cause the number of queuing actions to exceed <paramref name=\"maxQueuingActions\" />, a <see cref=\"BulkheadRejectedException\" /> is thrown.</para>\n    /// </summary>\n    /// <typeparam name=\"TResult\">The type of the result.</typeparam>\n    /// <param name=\"maxParallelization\">The maximum number of concurrent actions that may be executing through the policy.</param>\n    /// <param name=\"maxQueuingActions\">The maximum number of actions that may be queuing, waiting for an execution slot.</param>\n    /// <param name=\"onBulkheadRejected\">An action to call, if the bulkhead rejects execution due to oversubscription.</param>\n    /// <returns>The policy instance.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">maxParallelization;Value must be greater than zero.</exception>\n    /// <exception cref=\"ArgumentOutOfRangeException\">maxQueuingActions;Value must be greater than or equal to zero.</exception>\n    /// <exception cref=\"ArgumentNullException\">Thrown when <paramref name=\"onBulkheadRejected\"/> is <see langword=\"null\"/>.</exception>\n    public static BulkheadPolicy<TResult> Bulkhead<TResult>(int maxParallelization, int maxQueuingActions, Action<Context> onBulkheadRejected)\n    {\n        if (maxParallelization <= 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxParallelization), \"Value must be greater than zero.\");\n        }\n\n        if (maxQueuingActions < 0)\n        {\n            throw new ArgumentOutOfRangeException(nameof(maxQueuingActions), \"Value must be greater than or equal to zero.\");\n        }\n\n        if (onBulkheadRejected == null)\n        {\n            throw new ArgumentNullException(nameof(onBulkheadRejected));\n        }\n\n        return new BulkheadPolicy<TResult>(\n            maxParallelization,\n            maxQueuingActions,\n            onBulkheadRejected);\n    }\n}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/BulkheadTResultSyntax.cs#L41-L77","documentation":"Thrown as ArgumentOutOfRangeException(nameof(maxParallelization)) when constructing a generic BulkheadPolicy<TResult> via Policy.Bulkhead<TResult>(...) with maxParallelization <= 0. The guard at BulkheadTResultSyntax.cs:59–63 fires at construction time. This is the generic overload for result-returning bulkhead policies.","triggerScenarios":"Calling Policy.Bulkhead<TResult>(maxParallelization, ...) where maxParallelization is 0 or negative. Identical validation to the non-generic overload, but for the typed-return bulkhead.","commonSituations":"Configuration binding to a missing key that defaults to int 0. Formula computing processor-based parallelization that rounds to zero. Copy-paste of a configuration value from a different setting that was 0.","solutions":["Ensure maxParallelization is at least 1 when constructing the typed bulkhead policy","Provide a fallback default when reading from configuration","Validate at startup and log a clear error before the policy is built"],"exampleFix":"// before\nvar maxPar = int.Parse(config[\"MaxParallel\"]); // 0 if misconfigured\nvar policy = Policy.Bulkhead<string>(maxPar, 10, _ => { }); // throws\n\n// after\nvar maxPar = int.TryParse(config[\"MaxParallel\"], out var p) && p > 0 ? p : 10;\nvar policy = Policy.Bulkhead<string>(maxPar, 10, _ => { });","handlingStrategy":"validation","validationCode":"if (maxParallelization <= 0)\n{\n    throw new InvalidOperationException($\"Invalid maxParallelization: {maxParallelization}. Must be >= 1.\");\n}\nvar policy = Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions, onReject);","typeGuard":"public static bool IsValidParallelization(int value) => value > 0;","tryCatchPattern":null,"preventionTips":["Validate configuration values at startup before policy construction","Use TryParse with a sensible default when reading from configuration","Log the effective parallelization value for diagnostics"],"tags":["bulkhead","configuration","argument-validation","out-of-range","generic","construction"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}