{"record":{"id":"8e250af64f62be9c","repo":"dotnet/reactive","slug":"strings-linq-no-elements-listobservable","errorCode":null,"errorMessage":"Strings_Linq.NO_ELEMENTS","messagePattern":"Strings_Linq\\.NO_ELEMENTS","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Rx.NET/Source/src/System.Reactive/ListObservable.cs","lineNumber":57,"sourceCode":"        }\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();\n\n                if (_results.Count == 0)\n                {\n                    throw new InvalidOperationException(Strings_Linq.NO_ELEMENTS);\n                }\n\n                return _results[_results.Count - 1];\n            }\n        }\n        /// <summary>\n        /// Determines the index of a specific item in the ListObservable.\n        /// </summary>\n        /// <param name=\"item\">The element to determine the index for.</param>\n        /// <returns>The index of the specified item in the list; -1 if not found.</returns>\n        public int IndexOf(T item)\n        {\n            Wait();\n            return _results.IndexOf(item);\n        }\n\n        /// <summary>\n        /// Inserts an item to the ListObservable at the specified index.","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Rx.NET/Source/src/System.Reactive/ListObservable.cs#L39-L75","documentation":"ListObservable's Last property blocks until the source sequence terminates and then throws InvalidOperationException with Strings_Linq.NO_ELEMENTS if no elements were recorded (the list is empty). It is the non-blocking API equivalent of Last() with throw-on-empty semantics.","triggerScenarios":"Reading .Last on a ListObservable whose subscribed source completed (or errored) without emitting any OnNext values.","commonSituations":"Capturing the final value of a UI or test stream that never fired; source errored immediately so only an error notification was recorded, then code still asks for Last.","solutions":["Check Count/recorded results before reading Last and handle the empty case","Subscribe to the OnError notification (OnError property) first, since an errored source never yields a Last value","Catch InvalidOperationException around the property access"],"exampleFix":"// before\nvar last = listObservable.Last; // throws when empty\n// after\nif (listObservable.Count > 0) { var last = listObservable.Last; } else { /* handle empty */ }","handlingStrategy":"try-catch","validationCode":"if (listObservable.Count == 0) { /* handle empty */ } else { var last = listObservable.Last; }","typeGuard":null,"tryCatchPattern":"try { var last = listObservable.Last; } catch (InvalidOperationException) { /* no recorded elements */ }","preventionTips":["Check the recorded results count before reading Last","Inspect OnError first - an errored source leaves no Last value","Only read Last after the source has completed and emitted values"],"tags":["empty-sequence","blocking","rx","list-observable"],"backgroundTag":"empty-result-set","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"}