{"record":{"id":"6b77e5fb52030aea","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-zero-6b77e5","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/BulkheadSyntax.cs","lineNumber":55,"sourceCode":"    public static BulkheadPolicy Bulkhead(int maxParallelization, int maxQueuingActions)\n        => Bulkhead(maxParallelization, maxQueuingActions, EmptyAction);\n\n    /// <summary>\n    /// Builds a bulkhead isolation <see cref=\"Policy\" />, 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    /// <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 Bulkhead(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(\n            maxParallelization,\n            maxQueuingActions,\n            onBulkheadRejected);\n    }\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/BulkheadSyntax.cs#L37-L73","documentation":"Thrown as ArgumentOutOfRangeException(nameof(maxParallelization)) when constructing a non-generic BulkheadPolicy via Policy.Bulkhead(...) with maxParallelization <= 0. The guard at BulkheadSyntax.cs:55–59 fires at policy construction time, before any semaphores are created. maxParallelization controls how many actions may execute concurrently through the bulkhead.","triggerScenarios":"Calling Policy.Bulkhead(maxParallelization, ...) where maxParallelization is 0 or negative. Common when the value comes from configuration that defaults to 0 or is computed from a formula that yields a non-positive result.","commonSituations":"Reading maxParallelization from appsettings.json where the key is missing (binds to default int 0). Calculating parallelization as a percentage of processor count with rounding to zero. Environment variable not set, parsing to 0.","solutions":["Ensure the configuration value for maxParallelization is at least 1","Add a fallback default when reading from configuration: config.GetValue(\"MaxParallel\", 10)","Validate the value at application startup and fail fast with a clear message"],"exampleFix":"// before\nvar maxPar = config.GetValue<int>(\"Bulkhead:MaxParallelization\"); // 0 if missing\nvar policy = Policy.Bulkhead(maxPar, 10, _ => { }); // throws\n\n// after\nvar maxPar = config.GetValue<int>(\"Bulkhead:MaxParallelization\");\nif (maxPar <= 0) maxPar = Environment.ProcessorCount;\nvar policy = Policy.Bulkhead(maxPar, 10, _ => { });","handlingStrategy":"validation","validationCode":"if (maxParallelization <= 0)\n{\n    throw new InvalidOperationException($\"Invalid maxParallelization: {maxParallelization}. Must be >= 1.\");\n}\nvar policy = Policy.Bulkhead(maxParallelization, maxQueuingActions, onReject);","typeGuard":"public static bool IsValidParallelization(int value) => value > 0;","tryCatchPattern":null,"preventionTips":["Validate configuration values at startup and fail fast with a descriptive message","Use a named constant or configuration helper that enforces minimum values","Log the effective bulkhead configuration at startup for diagnostics"],"tags":["bulkhead","configuration","argument-validation","out-of-range","construction"],"backgroundTag":null,"analyzedSha":"d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac","analyzedAt":"2026-08-13T16:36:01.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}