{"record":{"id":"be6db688c5caee6e","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-bufferboundaries","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'bufferBoundaries')","messagePattern":"Value cannot be null\\. \\(Parameter 'bufferBoundaries'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs","lineNumber":182,"sourceCode":"            return CreateAsyncObservable<IList<TSource>>.From(\n                source,\n                (timeSpan, count, scheduler),\n                static async (source, state, observer) =>\n                {\n                    var (sink, timer) = await AsyncObserver.Buffer(observer, state.timeSpan, state.count, state.scheduler).ConfigureAwait(false);\n\n                    var subscription = await source.SubscribeSafeAsync(sink).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(subscription, timer);\n                });\n        }\n\n        public static IAsyncObservable<IList<TSource>> Buffer<TSource, TBufferBoundary>(this IAsyncObservable<TSource> source, IAsyncObservable<TBufferBoundary> bufferBoundaries)\n        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (bufferBoundaries == null)\n                throw new ArgumentNullException(nameof(bufferBoundaries));\n\n            return CreateAsyncObservable<IList<TSource>>.From(\n                source,\n                bufferBoundaries,\n                static async (source, bufferBoundaries, observer) =>\n                {\n                    var (sourceObserver, boundariesObserver) = AsyncObserver.Buffer<TSource, TBufferBoundary>(observer);\n\n                    var sourceSubscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);\n                    var boundariesSubscription = await bufferBoundaries.SubscribeSafeAsync(boundariesObserver).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(sourceSubscription, boundariesSubscription);\n                });\n        }\n\n        // REVIEW: This overload is inherited from Rx but arguably a bit esoteric as it doesn't provide context to the closing selector.\n\n        public static IAsyncObservable<IList<TSource>> Buffer<TSource, TBufferClosing>(this IAsyncObservable<TSource> source, Func<IAsyncObservable<TBufferClosing>> bufferClosingSelector)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs#L164-L200","documentation":"Genuine ArgumentNullException: the boundary overload Buffer(source, bufferBoundaries) requires a non-null boundary observable; it is used to subscribe to buffer-closing signals, so null is rejected up front.","triggerScenarios":"Calling Buffer(source, null); a boundaries factory method returning null; conditional logic that only sometimes creates the boundary stream.","commonSituations":"Boundary stream created from a timer/event emitter that failed to start; null returned from a lookup of an existing stream by key.","solutions":["Create a real boundary observable (e.g. from a timer or interval) before calling","Fall back to AsyncObservable.Never<TBoundary>() when no boundaries are needed","Guard the call site and use a time/count overload instead when boundaries are absent","Fix the boundary factory returning null"],"exampleFix":"// before\nvar buf = src.Buffer(boundaries);\n// after\nvar buf = src.Buffer(boundaries ?? AsyncObservable.Never<Unit>());","handlingStrategy":"type-guard","validationCode":"if (bufferBoundaries == null) bufferBoundaries = AsyncObservable.Never<TBufferBoundary>();","typeGuard":"static IAsyncObservable<B> NonNullBoundaries<B>(IAsyncObservable<B> b) => b ?? AsyncObservable.Never<B>();","tryCatchPattern":"try { var buf = source.Buffer(bufferBoundaries); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"bufferBoundaries\")\n{\n    // no boundaries available: fall back to time-based buffering\n    var buf = source.Buffer(TimeSpan.FromSeconds(10), 100);\n}","preventionTips":["Never return null boundary streams; use Never or Empty","Ensure boundary emitters (timers, events) are started before composition","Prefer switching to a time/count overload when boundaries are genuinely absent"],"tags":["null-reference","arguments","reactive","buffer-boundaries"],"backgroundTag":"null-argument","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"}