{"record":{"id":"53c91d792290f1e6","repo":"dotnet/reactive","slug":"observer-listobservable","errorCode":null,"errorMessage":"observer","messagePattern":"observer","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/ListObservable.cs","lineNumber":204,"sourceCode":"        public IEnumerator<T> GetEnumerator()\n        {\n            Wait();\n            return _results.GetEnumerator();\n        }\n\n        IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();\n\n        /// <summary>\n        /// Subscribes an observer to the ListObservable which will be notified upon completion.\n        /// </summary>\n        /// <param name=\"observer\">The observer to send completion or error messages to.</param>\n        /// <returns>The disposable resource that can be used to unsubscribe.</returns>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"observer\"/> is <c>null</c>.</exception>\n        public IDisposable Subscribe(IObserver<object> observer)\n        {\n            if (observer == null)\n            {\n                throw new ArgumentNullException(nameof(observer));\n            }\n\n            return StableCompositeDisposable.Create(_subscription, _subject.Subscribe(observer));\n        }\n    }\n}\n","sourceCodeStart":186,"sourceCodeEnd":211,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/ListObservable.cs#L186-L211","documentation":"ListObservable's Subscribe(IObserver<object>) replays recorded notifications via an internal subject and throws ArgumentNullException when 'observer' is null, because there is no meaningful subscription target.","triggerScenarios":"Calling listObservable.Subscribe(null), typically when the observer comes from a failed lookup, an uninitialized field, or a factory returning null.","commonSituations":"Test code building observers conditionally; a refactoring replaced a real observer with a null-returning helper; event-wiring code where the handler was never attached.","solutions":["Pass a valid IObserver<object> (e.g. AnonymousObserver) instead of null","Null-check the observer before subscribing","Fix the code path that produced a null observer"],"exampleFix":"// before\nlistObservable.Subscribe(maybeObserver); // may be null\n// after\nvar observer = maybeObserver ?? new AnonymousObserver<object>(x => Console.WriteLine(x));\nlistObservable.Subscribe(observer);","handlingStrategy":"validation","validationCode":"if (observer == null) throw new ArgumentNullException(nameof(observer));\nlistObservable.Subscribe(observer);","typeGuard":"static bool IsValidObserver(IObserver<object> o) => o != null;","tryCatchPattern":"try { listObservable.Subscribe(observer); } catch (ArgumentNullException) { /* null observer */ }","preventionTips":["Create observers explicitly (AnonymousObserver) rather than from nullable sources","Null-check observers in subscription wiring code","Avoid factory helpers that can return null observers"],"tags":["null-argument","rx","list-observable","subscribe"],"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"}