dotnet/reactive · error · InvalidOperationException
The subject has no value.
Error message
The subject has no value.
What it means
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.'
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
Example fix
// before var value = await subject; // throws if subject completed empty // after var value = hasPublishedValue ? await subject : defaultValue;
Defensive patterns
Strategy: validation
Validate before calling
if (subject.CompletionStatus == AsyncSubjectStatus.CompletedWithoutValue) useDefaultInstead();
Type guard
bool HasResult(AsyncAsyncSubject<T> s) => s.HasReceivedValue;
Try / catch
try { value = await subject; } catch (InvalidOperationException ex) when (ex.Message == "The subject has no value.") { value = defaultValue; } Prevention
- 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
When it happens
Trigger: Calling GetResult on an AsyncAsyncSubject that completed via OnCompleted without any OnNext, i.e. _hasValue is false and _error is null.
Common situations: 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.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- AdvanceTo cannot be called when the scheduler is already…
- AdvanceBy cannot be called when the scheduler is already…
- subject
- error
- error
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/5f24253a686b9fe4.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Subjects/AsyncAsyncSubject.cs:175
public T GetResult()
{
if (!IsCompleted)
{
var e = new ManualResetEventSlim(initialState: false);
OnCompleted(() => { e.Set(); }, originalContext: false);
e.Wait();
}
if (_error != null)
{
ExceptionDispatchInfo.Capture(_error).Throw();
}
if (!_hasValue)
{
throw new InvalidOperationException("The subject has no value.");
}
return _value;
}
public void OnCompleted(Action continuation)
{
if (continuation == null)
throw new ArgumentNullException(nameof(continuation));
OnCompleted(continuation, originalContext: true);
}
private void OnCompleted(Action continuation, bool originalContext)
{
var subscribeTask = SubscribeAsync(new AwaitObserver(continuation, originalContext));
subscribeTask.AsTask().ContinueWith(t =>View on GitHub (pinned to 94b5d5ab91)