{"record":{"id":"fadf2bb6574d6b61","repo":"App-vNext/Polly","slug":"value-must-be-greater-than-or-equal-to-zero-fadf2b","errorCode":null,"errorMessage":"Value must be greater than or equal to zero.","messagePattern":"Value must be greater than or equal to zero\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Polly/Bulkhead/BulkheadTResultSyntax.cs","lineNumber":64,"sourceCode":"    /// </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}\n","sourceCodeStart":46,"sourceCodeEnd":78,"githubUrl":"https://github.com/App-vNext/Polly/blob/d0e46bdb1ee11ea50d0e4b6846d2633d6bc09bac/src/Polly/Bulkhead/BulkheadTResultSyntax.cs#L46-L78","documentation":"Thrown as ArgumentOutOfRangeException(nameof(maxQueuingActions)) when constructing a generic BulkheadPolicy<TResult> via Policy.Bulkhead<TResult>(...) with maxQueuingActions < 0. The guard at BulkheadTResultSyntax.cs:64–68 fires at construction time. Zero is valid (no queue); negative values are rejected.","triggerScenarios":"Calling Policy.Bulkhead<TResult>(maxParallelization, maxQueuingActions, ...) where maxQueuingActions is negative. Happens when the queue depth is computed or configured to a negative value.","commonSituations":"Arithmetic on queue depth that overshoots into negatives. Configuration key missing or misparsed to a negative number. Inheriting a queue-size formula from a non-generic context that produces different results.","solutions":["Ensure maxQueuingActions is 0 or positive (0 disables the queue entirely)","Clamp the value: Math.Max(0, computedQueueDepth)","Validate and log at startup before constructing the policy"],"exampleFix":"// before\nint queueDepth = baseQueue - reserveSlots; // may be negative\nvar policy = Policy.Bulkhead<string>(10, queueDepth, _ => { }); // throws\n\n// after\nint queueDepth = Math.Max(0, baseQueue - reserveSlots);\nvar policy = Policy.Bulkhead<string>(10, queueDepth, _ => { });","handlingStrategy":"validation","validationCode":"int safeQueue = Math.Max(0, maxQueuingActions);\nvar policy = Policy.Bulkhead<TResult>(maxParallelization, safeQueue, onReject);","typeGuard":"public static bool IsValidQueueDepth(int value) => value >= 0;","tryCatchPattern":null,"preventionTips":["Clamp queue depth to 0 with Math.Max when computing from formulas","Validate at startup with clear messages","Test edge cases in configuration parsing (negative values from arithmetic)"],"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"}