{"record":{"id":"5b1ccd61d87ae8ba","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-buffer","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs","lineNumber":228,"sourceCode":"                static async (source, bufferClosingSelector, observer) =>\n                {\n                    var (sourceObserver, closingDisposable) = await AsyncObserver.Buffer<TSource, TBufferClosing>(observer, bufferClosingSelector).ConfigureAwait(false);\n\n                    var sourceSubscription = await source.SubscribeSafeAsync(sourceObserver).ConfigureAwait(false);\n\n                    return StableCompositeAsyncDisposable.Create(sourceSubscription, closingDisposable);\n                });\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> Buffer<TSource>(IAsyncObserver<IList<TSource>> observer, int count) => Buffer(observer, count, count);\n\n        public static IAsyncObserver<TSource> Buffer<TSource>(IAsyncObserver<IList<TSource>> observer, int count, int skip)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n            if (count <= 0)\n                throw new ArgumentNullException(nameof(count));\n            if (skip <= 0)\n                throw new ArgumentNullException(nameof(skip));\n\n            var queue = new Queue<IList<TSource>>();\n            var n = 0;\n\n            void CreateBuffer() => queue.Enqueue(new List<TSource>());\n\n            CreateBuffer();\n\n            return Create<TSource>(\n                async x =>\n                {\n                    foreach (var buffer in queue)\n                    {\n                        buffer.Add(x);","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs#L210-L246","documentation":"System.Reactive.Async's Buffer operator requires a downstream IAsyncObserver<IList<TSource>> to emit buffered lists to. The Buffer(observer, count) overload immediately calls Buffer(observer, count, count), and the target overload validates that observer is not null via ArgumentNullException(nameof(observer)). Passing null means the operator has nowhere to forward notifications, so it fails fast before subscribing anything.","triggerScenarios":"Calling Buffer<TSource>(null, 5) or Buffer<TSource>(null, 5, 5) — the count/count overloads in AsyncRx.NET/System.Reactive.Async/Linq/Operators/Buffer.cs:224-232 — with a null IAsyncObserver<IList<TSource>> as the first argument.","commonSituations":"Chaining operators where an earlier composition step returned null (e.g. a factory method silently failed); refactoring custom observable pipelines where the observer variable was never initialized; misusing the extension-style API by hand-rolling pipelines instead of fluent chaining so the observer argument gets forgotten.","solutions":["Pass a valid IAsyncObserver<IList<TSource>> (or use the fluent extension overloads on the source so the observer is supplied automatically).","Check why the expression producing the observer evaluated to null — fix the upstream factory/step instead of the Buffer call.","Add a null guard or Debug.Assert at the pipeline construction site to fail before entering the operator."],"exampleFix":"// before\nIAsyncObserver<IList<int>> sink = GetSink(); // may return null\nvar buf = Buffer(sink, 3);\n// after\nIAsyncObserver<IList<int>> sink = GetSink() ?? throw new InvalidOperationException(\"sink factory returned null\");\nvar buf = Buffer(sink, 3);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nBuffer(observer, count);","typeGuard":"static bool IsValidObserver<TSource>(IAsyncObserver<IList<TSource>> o) => o is not null;","tryCatchPattern":"try { var buf = Buffer(observer, count); } catch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* supply a valid observer or abort pipeline construction */ }","preventionTips":["Use the fluent extension overloads so the observer is threaded through automatically","Never store pipeline sinks in nullable fields that are read before assignment","Assert non-null at pipeline construction boundaries"],"tags":["argument-null","reactive-extensions","buffer-operator"],"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"}