{"record":{"id":"5f24253a686b9fe4","repo":"dotnet/reactive","slug":"the-subject-has-no-value","errorCode":null,"errorMessage":"The subject has no value.","messagePattern":"The subject has no value\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"AsyncRx.NET/System.Reactive.Async/Subjects/AsyncAsyncSubject.cs","lineNumber":175,"sourceCode":"        public T GetResult()\n        {\n            if (!IsCompleted)\n            {\n                var e = new ManualResetEventSlim(initialState: false);\n\n                OnCompleted(() => { e.Set(); }, originalContext: false);\n\n                e.Wait();\n            }\n\n            if (_error != null)\n            {\n                ExceptionDispatchInfo.Capture(_error).Throw();\n            }\n\n            if (!_hasValue)\n            {\n                throw new InvalidOperationException(\"The subject has no value.\");\n            }\n\n            return _value;\n        }\n\n        public void OnCompleted(Action continuation)\n        {\n            if (continuation == null)\n                throw new ArgumentNullException(nameof(continuation));\n\n            OnCompleted(continuation, originalContext: true);\n        }\n\n        private void OnCompleted(Action continuation, bool originalContext)\n        {\n            var subscribeTask = SubscribeAsync(new AwaitObserver(continuation, originalContext));\n\n            subscribeTask.AsTask().ContinueWith(t =>","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/AsyncRx.NET/System.Reactive.Async/Subjects/AsyncAsyncSubject.cs#L157-L193","documentation":"AsyncAsyncSubject<T>.GetResult blocks/awaits until the subject completes and then returns the last emitted value. If the subject completed without ever receiving a value (only OnCompleted, or an error was already rethrown), there is no value to return and the subject throws InvalidOperationException with the message 'The subject has no value.'","triggerScenarios":"Calling GetResult on an AsyncAsyncSubject that completed via OnCompleted without any OnNext, i.e. _hasValue is false and _error is null.","commonSituations":"Awaiting an async subject that a producer completed without publishing; race where the producer finished early due to a cancellation or empty branch of a pipeline.","solutions":["Ensure the producer calls OnNext at least once before OnCompleted","Check _hasValue semantics: only await/GetResult when the pipeline guarantees a value","Handle the empty-completion case explicitly (e.g. a default value) instead of calling GetResult"],"exampleFix":"// before\nvar value = await subject; // throws if subject completed empty\n// after\nvar value = hasPublishedValue ? await subject : defaultValue;","handlingStrategy":"validation","validationCode":"if (subject.CompletionStatus == AsyncSubjectStatus.CompletedWithoutValue) useDefaultInstead();","typeGuard":"bool HasResult(AsyncAsyncSubject<T> s) => s.HasReceivedValue;","tryCatchPattern":"try { value = await subject; } catch (InvalidOperationException ex) when (ex.Message == \"The subject has no value.\") { value = defaultValue; }","preventionTips":["Guarantee the producer emits OnNext before OnCompleted","Handle empty pipelines with defaults before awaiting","Treat awaiting an empty subject as a programming bug, not a runtime condition"],"tags":["rx","subject","invalid-operation","empty-value"],"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"}