{"record":{"id":"f3fb14dd1c131e35","repo":"dotnet/reactive","slug":"count","errorCode":null,"errorMessage":"count","messagePattern":"count","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Skip.cs","lineNumber":19,"sourceCode":"﻿// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT License.\n// See the LICENSE file in the project root for more information. \n\nusing System.Reactive.Concurrency;\nusing System.Reactive.Disposables;\nusing System.Threading;\nusing System.Threading.Tasks;\n\nnamespace System.Reactive.Linq\n{\n    public partial class AsyncObservable\n    {\n        public static IAsyncObservable<TSource> Skip<TSource>(this IAsyncObservable<TSource> source, int count)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (count < 0)\n                throw new ArgumentOutOfRangeException(nameof(count));\n\n            if (count == 0)\n            {\n                return source;\n            }\n\n            return CreateAsyncObservable<TSource>.From(\n                source,\n                count,\n                static (source, count, observer) => source.SubscribeSafeAsync(AsyncObserver.Skip(observer, count)));\n        }\n\n        public static IAsyncObservable<TSource> Skip<TSource>(this IAsyncObservable<TSource> source, TimeSpan duration)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (duration < TimeSpan.Zero)\n                throw new ArgumentOutOfRangeException(nameof(duration));","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Skip.cs#L1-L37","documentation":"Skip(source, count) throws ArgumentOutOfRangeException with paramName \"count\" when the caller passes a negative skip count. The library requires count >= 0; a negative count has no meaningful semantics (skipping fewer than zero elements).","triggerScenarios":"Calling Skip(source, count) with a negative int, e.g. from an unvalidated user input or an arithmetic result that underflowed (count = taken - requested with taken < requested).","commonSituations":"Computing a skip count from paging math (page-1)*size where page is 0 or negative; subtracting counters that can go below zero; passing deserialized config values without validation.","solutions":["Ensure the count passed to Skip is >= 0 before calling","Clamp with Math.Max(0, count) when the value is derived from arithmetic or user input","Fix paging math so page numbers are 1-based or clamped to at least 1"],"exampleFix":"// before\nvar skip = (page - 1) * pageSize;\nvar result = source.Skip(skip);\n// after\nvar skip = Math.Max(0, (page - 1) * pageSize);\nvar result = source.Skip(skip);","handlingStrategy":"validation","validationCode":"if (count < 0) throw new ArgumentException(\"count must be >= 0\", nameof(count));\nsource.Skip(count);","typeGuard":null,"tryCatchPattern":"try { var res = source.Skip(count); }\ncatch (ArgumentOutOfRangeException ex) when (ex.ParamName == \"count\") { /* clamp and retry */ }","preventionTips":["Clamp derived skip values with Math.Max(0, count)","Validate paging inputs (page >= 1, size >= 0) at the boundary","Never pass raw user input as a skip count without validation"],"tags":["argument-out-of-range","rx","validation"],"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-15T23:17:13.987Z"}