{"record":{"id":"50eaff568d6e377d","repo":"dotnet/reactive","slug":"argumentoutofrangeexception-default-message-specified","errorCode":null,"errorMessage":"ArgumentOutOfRangeException (default message: Specified argument was out of the range of valid values. (Parameter 'count'))","messagePattern":"ArgumentOutOfRangeException \\(default message: Specified argument was out of the range of valid values\\. \\(Parameter 'count'\\)\\)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs","lineNumber":770,"sourceCode":"        /// <param name=\"source\">Source sequence.</param>\n        /// <param name=\"count\">Number of elements to bypass at the end of the source sequence.</param>\n        /// <returns>An observable sequence containing the source sequence elements except for the bypassed ones at the end.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is null.</exception>\n        /// <exception cref=\"ArgumentOutOfRangeException\"><paramref name=\"count\"/> is less than zero.</exception>\n        /// <remarks>\n        /// This operator accumulates a queue with a length enough to store the first <paramref name=\"count\"/> elements. As more elements are\n        /// received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.\n        /// </remarks>\n        public static IObservable<TSource> SkipLast<TSource>(this IObservable<TSource> source, int count)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            if (count < 0)\n            {\n                throw new ArgumentOutOfRangeException(nameof(count));\n            }\n\n            return s_impl.SkipLast(source, count);\n        }\n\n        #endregion\n\n        #region + StartWith +\n\n        /// <summary>\n        /// Prepends a sequence of values to an observable sequence.\n        /// </summary>\n        /// <typeparam name=\"TSource\">The type of the elements in the source sequence.</typeparam>\n        /// <param name=\"source\">Source sequence to prepend values to.</param>\n        /// <param name=\"values\">Values to prepend to the specified sequence.</param>\n        /// <returns>The source sequence prepended with the specified values.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> or <paramref name=\"values\"/> is null.</exception>\n        public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, params TSource[] values)","sourceCodeStart":752,"sourceCodeEnd":788,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/Linq/Observable.Single.cs#L752-L788","documentation":"SkipLast bypasses a number of trailing elements; the documented ArgumentOutOfRangeException fires when count is less than zero, since a negative bypass count is invalid. Fix: pass 0 or a positive count.","triggerScenarios":"Calling SkipLast(source, count) where count < 0, typically a computed value like `take - skip` or an unvalidated user/config value.","commonSituations":"Arithmetic on counts where the subtracted value exceeds the taken value; config or CLI-supplied sizes parsed without range validation.","solutions":["Clamp with Math.Max(0, count) before calling.","Validate the numeric input at the configuration boundary.","Fix the subtraction/logic producing the negative count.","Use SkipLast(0) explicitly when 'skip nothing' is the intent."],"exampleFix":"// before\nvar result = source.SkipLast(take - skip);\n// after\nvar result = source.SkipLast(Math.Max(0, take - skip));","handlingStrategy":"validation","validationCode":"if (count < 0) throw new ArgumentOutOfRangeException(nameof(count));\nvar result = source.SkipLast(count);","typeGuard":"bool IsValidCount(int n) => n >= 0;","tryCatchPattern":"try { result = source.SkipLast(n); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"count\") { result = source; }","preventionTips":["Clamp computed sizes with Math.Max(0, ...).","Validate config/CLI numeric values at parse time.","Add range assertions in helpers that derive skip counts."],"tags":["rx","argument-out-of-range","skiplast"],"backgroundTag":"argument-out-of-range","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}