{"record":{"id":"e47e982c484905db","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-count","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'count')","messagePattern":"Value cannot be null\\. \\(Parameter 'count'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs","lineNumber":20,"sourceCode":"// 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.Collections.Generic;\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<IList<TSource>> Buffer<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 ArgumentNullException(nameof(count));\n\n            return CreateAsyncObservable<IList<TSource>>.From(\n                source,\n                count,\n                static (source, count, observer) => source.SubscribeSafeAsync(AsyncObserver.Buffer(observer, count)));\n        }\n\n        public static IAsyncObservable<IList<TSource>> Buffer<TSource>(this IAsyncObservable<TSource> source, int count, int skip)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (count <= 0)\n                throw new ArgumentNullException(nameof(count));\n            if (skip <= 0)\n                throw new ArgumentNullException(nameof(skip));\n\n            return CreateAsyncObservable<IList<TSource>>.From(\n                source,","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs#L2-L38","documentation":"Buffer<TSource>(source, count) throws ArgumentNullException(nameof(count)) when count <= 0. Note this is actually an argument-range problem: a non-positive buffer size is invalid because a batch must contain at least one element, but the library throws ArgumentNullException with the parameter name 'count'. The check runs at operator composition time, before any subscription.","triggerScenarios":"Calling source.Buffer(0), source.Buffer(-1), or Buffer with a count computed from configuration/user input that is 0 or negative (e.g. pageSize = 0 from an unset setting).","commonSituations":"Batch size read from app configuration or a query-string parameter defaulting to 0; integer arithmetic producing 0 (e.g. batchSize = total / 0-safe divisor); uninitialized int fields passed straight through.","solutions":["Pass a positive count (>= 1); clamp or default before calling: count = Math.Max(1, configuredCount).","Validate configuration feeding the batch size at startup and fail with a clear domain error if it is <= 0.","Catch ArgumentNullException('count') and surface a message telling the user the batch size must be positive."],"exampleFix":"// before\nvar batches = source.Buffer(batchSize); // batchSize could be 0 from config\n// after\nif (batchSize <= 0) batchSize = 1; // or throw a domain-specific error\nvar batches = source.Buffer(batchSize);","handlingStrategy":"validation","validationCode":"if (count <= 0) throw new ArgumentException(\"Buffer count must be >= 1\", nameof(count));","typeGuard":"bool IsValidBufferSize(int count) => count > 0;","tryCatchPattern":"try { var batches = source.Buffer(count); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"count\") { throw new InvalidOperationException(\"Batch size must be positive; check configuration\", ex); }","preventionTips":["Clamp configured batch sizes: count = Math.Max(1, count)","Validate batch-size configuration at startup, not at pipeline build","Never use -1/0 sentinels for 'unset' sizes without validating before use"],"tags":["argumentnull","argument-range","asyncrx","buffer","count"],"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"}