{"record":{"id":"28205a2a6a7c8cc4","repo":"dotnet/reactive","slug":"value-cannot-be-null-parameter-observer-longcount","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'observer')","messagePattern":"Value cannot be null\\. \\(Parameter 'observer'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Linq/Operators/LongCount.cs","lineNumber":51,"sourceCode":"        {\n            if (source == null)\n                throw new ArgumentNullException(nameof(source));\n            if (predicate == null)\n                throw new ArgumentNullException(nameof(predicate));\n\n            return CreateAsyncObservable<long>.From(\n                source,\n                predicate,\n                static (source, predicate, observer) => source.SubscribeSafeAsync(AsyncObserver.LongCount(observer, predicate)));\n        }\n    }\n\n    public partial class AsyncObserver\n    {\n        public static IAsyncObserver<TSource> LongCount<TSource>(IAsyncObserver<long> observer)\n        {\n            if (observer == null)\n                throw new ArgumentNullException(nameof(observer));\n\n            var count = 0L;\n\n            return Create<TSource>(\n                async x =>\n                {\n                    try\n                    {\n                        checked\n                        {\n                            count++;\n                        }\n                    }\n                    catch (Exception ex)\n                    {\n                        await observer.OnErrorAsync(ex).ConfigureAwait(false);\n                        return;\n                    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Linq/Operators/LongCount.cs#L33-L69","documentation":"AsyncObserver.LongCount<TSource>(IAsyncObserver<long>) at LongCount.cs:51 creates the counting observer stage and requires a non-null downstream observer to forward the final count and completion to. A null observer means there is no consumer, so ArgumentNullException is thrown.","triggerScenarios":"Calling AsyncObserver.LongCount<TSource>(null) when composing custom observer pipelines.","commonSituations":"Custom operator authors wiring observer chains where the downstream observer came from a nullable field or an earlier factory call that returned null.","solutions":["Pass the observer you are forwarding to (typically the one received in your SubscribeAsync delegate).","Check your custom operator wiring: the downstream observer must be resolved before constructing LongCount.","If the downstream may be absent, delay observer construction until subscription time when the real observer is available."],"exampleFix":"// before\nreturn AsyncObserver.LongCount<T>(downstream); // downstream null\n// after\nif (downstream == null) throw new ArgumentNullException(nameof(downstream));\nreturn AsyncObserver.LongCount<T>(downstream);","handlingStrategy":"validation","validationCode":"if (observer is null) throw new ArgumentNullException(nameof(observer));\nvar counting = AsyncObserver.LongCount<T>(observer);","typeGuard":"static bool HasDownstream<T>(IAsyncObserver<long>? o) => o is not null;","tryCatchPattern":"try { var stage = AsyncObserver.LongCount<T>(observer); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"observer\") { /* fix observer wiring */ throw; }","preventionTips":["In custom operators, always build observer chains inside the SubscribeAsync callback where the real observer is in scope.","Never store the downstream observer in a nullable field set later.","Assert observer non-null at the top of custom operator factories."],"tags":["csharp","argument-null","observer","asyncrx"],"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"}