{"record":{"id":"18ce09b1f90f4a0b","repo":"dotnet/csharplang","slug":"argumentexpression-argument-cannot-be-greate","errorCode":null,"errorMessage":"{argumentExpression} ({argument}) cannot be greater than {highExpression} ({high}).","messagePattern":"(.+?) \\((.+?)\\) cannot be greater than (.+?) \\((.+?)\\)\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"proposals/csharp-10.0/caller-argument-expression.md","lineNumber":101,"sourceCode":"    public static void Argument(bool condition, string message, [CallerArgumentExpression(\"condition\")] string conditionExpression = null)\n    {\n        if (!condition) throw new ArgumentException(message: message, paramName: conditionExpression);\n    }\n\n    public static void InRange(int argument, int low, int high,\n        [CallerArgumentExpression(\"argument\")] string argumentExpression = null,\n        [CallerArgumentExpression(\"low\")] string lowExpression = null,\n        [CallerArgumentExpression(\"high\")] string highExpression = null)\n    {\n        if (argument < low)\n        {\n            throw new ArgumentOutOfRangeException(paramName: argumentExpression,\n                message: $\"{argumentExpression} ({argument}) cannot be less than {lowExpression} ({low}).\");\n        }\n\n        if (argument > high)\n        {\n            throw new ArgumentOutOfRangeException(paramName: argumentExpression,\n                message: $\"{argumentExpression} ({argument}) cannot be greater than {highExpression} ({high}).\");\n        }\n    }\n\n    public static void NotNull<T>(T argument, [CallerArgumentExpression(\"argument\")] string argumentExpression = null)\n        where T : class\n    {\n        if (argument == null) throw new ArgumentNullException(paramName: argumentExpression);\n    }\n}\n\nstatic T Single<T>(this T[] array)\n{\n    Verify.NotNull(array); // paramName: \"array\"\n    Verify.Argument(array.Length == 1, \"Array must contain a single element.\"); // paramName: \"array.Length == 1\"\n\n    return array[0];\n}","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/dotnet/csharplang/blob/05eb4800fc3dc76259ccd49ac01f1eeb49222380/proposals/csharp-10.0/caller-argument-expression.md#L83-L119","documentation":"Thrown by the example `InRange(int argument, int low, int high)` helper from the caller-argument-expression proposal when `argument > high`. As with the low-bound case, the message uses CallerArgumentExpression to print the offending expression, its value, and the upper bound.","triggerScenarios":"Calling `InRange(x, low, high)` with `x > high`. Supplying a size, index, or quantity that exceeds a hard cap (buffer length, column count, max items).","commonSituations":"Page numbers / page sizes above the configured maximum; array offsets computed without subtracting the length; values read from external services or config that exceed local limits; integer math that wraps or overflows an upper bound.","solutions":["Confirm the value is within `[low, high]` before the call and branch on the overflow with a domain-specific message.","Clamp with `Math.Clamp(argument, low, high)` when truncation to the ceiling is acceptable behavior.","Raise or correctly compute `high` (e.g. `collection.Count - 1`) if the bound itself was wrong.","Fix the source of the value so out-of-range quantities are rejected at the trust boundary."],"exampleFix":"// before\nGuard.InRange(index, 0, list.Count);\n\n// after\nint safeIndex = Math.Clamp(index, 0, list.Count - 1);\nGuard.InRange(safeIndex, 0, list.Count - 1);","handlingStrategy":"validation","validationCode":"static int Bounded(int value, int low, int high)\n{\n    if (value > high) throw new ArgumentOutOfRangeException(nameof(value), $\"{value} > {high}\");\n    return value;\n}","typeGuard":"static bool IsAtMost(int value, int high) => value <= high;","tryCatchPattern":"try { Guard.InRange(value, low, high); }\ncatch (ArgumentOutOfRangeException ex) when (value > high)\n{\n    // truncate to high or propagate a domain-specific error\n}","preventionTips":["Compute upper bounds from real sizes (`count - 1`) rather than magic numbers.","Clamp externally sourced values before they enter bounded APIs.","Add boundary tests at exactly `high` and `high + 1`."],"tags":["range","argument-validation","int","csharp"],"backgroundTag":null,"analyzedSha":"05eb4800fc3dc76259ccd49ac01f1eeb49222380","analyzedAt":"2026-08-13T17:44:03.908Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}