{"record":{"id":"5bffae911b216eac","repo":"devlooped/moq","slug":"argumentoutofrangeexception-callcountto-invalid-range-bounds","errorCode":null,"errorMessage":"ArgumentOutOfRangeException: callCountTo (invalid range bounds for Times.Between with Range.Exclusive)","messagePattern":"ArgumentOutOfRangeException: callCountTo \\(invalid range bounds for Times\\.Between with Range\\.Exclusive\\)","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Moq/Times.cs","lineNumber":124,"sourceCode":"        ///   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\n        /// <summary>\n        ///   Specifies that a mocked method should be invoked exactly\n        ///   <paramref name=\"callCount\"/> times.\n        /// </summary>\n        /// <param name=\"callCount\">The times that a method or property can be called.</param>","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/devlooped/moq/blob/89a5be629c752960fe403e95ff583e4ae6f00542/src/Moq/Times.cs#L106-L142","documentation":"For Times.Between with Range.Exclusive, when from and to differ by exactly 1 there is no integer strictly between them, so the call throws ArgumentOutOfRangeException named callCountTo. This is the 'empty exclusive range' check that complements the callCountFrom bounds check.","triggerScenarios":"Times.Between(2, 3, Range.Exclusive), Times.Between(5, 6, Range.Exclusive) — any exclusive interval with to - from == 1 (after the from/to ordering checks pass).","commonSituations":"Translating inclusive requirements ('at least 2, at most 3') into Exclusive range by mistake; dynamic bounds that happen to be adjacent.","solutions":["Use Range.Inclusive for adjacent bounds: Times.Between(2, 3, Range.Inclusive)","Widen the exclusive bounds by one (Between(1, 4, Exclusive)) if exclusivity is truly required","Validate to - from > 1 before calling with Range.Exclusive"],"exampleFix":"// before\nmock.Verify(m => m.Foo(), Times.Between(2, 3, Range.Exclusive));\n// after\nmock.Verify(m => m.Foo(), Times.Between(2, 3, Range.Inclusive));","handlingStrategy":"validation","validationCode":"if (to - from > 1)\n    mock.Verify(m => m.Foo(), Times.Between(from, to, Range.Exclusive));\nelse\n    mock.Verify(m => m.Foo(), Times.Between(from, to, Range.Inclusive));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Exclusive ranges need a gap: to - from >= 2","Default to Range.Inclusive unless exclusivity is explicit","Test boundary configurations of expected call counts"],"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"}