{"record":{"id":"561f0305da47ca4a","repo":"dotnet/reactive","slug":"source-listobservable","errorCode":null,"errorMessage":"source","messagePattern":"source","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/ListObservable.cs","lineNumber":35,"sourceCode":"    /// </summary>\n    /// <typeparam name=\"T\">The type of elements received from the source sequence.</typeparam>\n    [Experimental]\n    public class ListObservable<T> : IList<T>, IObservable<object>\n    {\n        private readonly IDisposable _subscription;\n        private readonly AsyncSubject<object> _subject = new();\n        private readonly List<T> _results = [];\n\n        /// <summary>\n        /// Constructs an object that retains the values of source and signals the end of the sequence.\n        /// </summary>\n        /// <param name=\"source\">The observable sequence whose elements will be retained in the list.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"source\"/> is <c>null</c>.</exception>\n        public ListObservable(IObservable<T> source)\n        {\n            if (source == null)\n            {\n                throw new ArgumentNullException(nameof(source));\n            }\n\n            _subscription = source.Subscribe(_results.Add, _subject.OnError, _subject.OnCompleted);\n        }\n\n        private void Wait()\n        {\n            _subject.DefaultIfEmpty().Wait();\n        }\n\n        /// <summary>\n        /// Returns the last value of the observable sequence.\n        /// </summary>\n        public T Value\n        {\n            get\n            {\n                Wait();","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/ListObservable.cs#L17-L53","documentation":"The ListObservable constructor subscribes to the given source and throws ArgumentNullException when 'source' is null, since the observable to record is required to build the internal results list and subject.","triggerScenarios":"Constructing new ListObservable<T>(null), e.g. passing an uninitialized observable field or a factory result that was null.","commonSituations":"Test harness code capturing notifications from a stream whose setup failed silently; DI/wiring produced null for the source observable.","solutions":["Pass a valid IObservable<T> instance (use Observable.Never<T>() or Empty as a placeholder if needed)","Null-check the source before constructing ListObservable","Fix the factory/dependency that returned null"],"exampleFix":"// before\nvar obs = new ListObservable<int>(maybeSource); // may be null\n// after\nif (maybeSource == null) maybeSource = Observable.Empty<int>();\nvar obs = new ListObservable<int>(maybeSource);","handlingStrategy":"validation","validationCode":"if (source == null) throw new ArgumentNullException(nameof(source));\nvar obs = new ListObservable<T>(source);","typeGuard":"static bool IsObservable<T>(IObservable<T> s) => s != null;","tryCatchPattern":"try { var obs = new ListObservable<int>(source); } catch (ArgumentNullException) { /* null source */ }","preventionTips":["Null-check observables before constructing recording wrappers","Default to Observable.Never<T>() when a real source is unavailable","Ensure stream factories never return null"],"tags":["null-argument","rx","list-observable","constructor"],"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"}