{"record":{"id":"259c499d78f78bd6","repo":"devlooped/moq","slug":"argumentoutofrangeexception-callcountfrom-invalid-range","errorCode":null,"errorMessage":"ArgumentOutOfRangeException: callCountFrom (invalid range bounds for Times.Between with Range.Exclusive)","messagePattern":"ArgumentOutOfRangeException: callCountFrom \\(invalid range bounds for Times\\.Between with Range\\.Exclusive\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Moq/Times.cs","lineNumber":119,"sourceCode":"        {\n            return new Times(Kind.AtMostOnce, 0, 1);\n        }\n\n        /// <summary>\n        ///   Specifies that a mocked method should be invoked between\n        ///   <paramref name=\"callCountFrom\"/> and <paramref name=\"callCountTo\"/> times.\n        /// </summary>\n        /// <param name=\"callCountFrom\">The minimum number of times.</param>\n        /// <param name=\"callCountTo\">The maximum number of times.</param>\n        /// <param name=\"rangeKind\">The kind of range. See <see cref=\"Range\"/>.</param>\n        /// <returns>An object defining the allowed number of invocations.</returns>\n        public static Times Between(int callCountFrom, int callCountTo, Range rangeKind)\n        {\n            if (rangeKind == Range.Exclusive)\n            {\n                if (callCountFrom <= 0 || callCountTo <= callCountFrom)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(callCountFrom));\n                }\n\n                if (callCountTo - callCountFrom == 1)\n                {\n                    throw new ArgumentOutOfRangeException(nameof(callCountTo));\n                }\n\n                return new Times(Kind.BetweenExclusive, callCountFrom + 1, callCountTo - 1);\n            }\n\n            if (callCountFrom < 0 || callCountTo < callCountFrom)\n            {\n                throw new ArgumentOutOfRangeException(nameof(callCountFrom));\n            }\n\n            return new Times(Kind.BetweenInclusive, callCountFrom, callCountTo);\n        }\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Times.cs#L101-L137","documentation":"Times.Between(from, to, Range.Exclusive) requires from >= 1 and to > from; the exclusive range must contain at least one valid value. Violating this throws ArgumentOutOfRangeException named callCountFrom. Additionally to - from must not equal 1, otherwise no integer lies strictly between them (that throws for callCountTo).","triggerScenarios":"Calling Times.Between(0, n, Range.Exclusive), Times.Between(negative, ...), or Between(a, b, Exclusive) where b <= a.","commonSituations":"Passing 0 as the lower bound assuming inclusive semantics; computing bounds dynamically where from ends up 0 or greater than to.","solutions":["Ensure from >= 1 and to > from for the exclusive variant","Use Range.Inclusive if zero should be a valid lower bound (with to >= from)","Precompute and validate bounds before the call"],"exampleFix":"// before\nmock.Verify(m => m.Foo(), Times.Between(0, 5, Range.Exclusive));\n// after\nmock.Verify(m => m.Foo(), Times.Between(1, 5, Range.Exclusive)); // or Range.Inclusive with 0","handlingStrategy":"validation","validationCode":"if (from >= 1 && to > from)\n    mock.Verify(m => m.Foo(), Times.Between(from, to, Range.Exclusive));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember Exclusive requires from >= 1 and at least one integer between bounds","Use Inclusive when 0 or adjacent bounds are intended","Add assertions on bounds before constructing Times"],"tags":["argument-out-of-range","moq","verification"],"backgroundTag":"argument-out-of-range","analyzedSha":"89a5be629c752960fe403e95ff583e4ae6f00542","analyzedAt":"2026-09-16T05:31:39.496Z","contentChangedAt":"2026-09-16T05:31:39.496Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}