dotnet/reactive · error · InvalidOperationException
Accept should have called only one IObserver<T> method
Error message
Accept should have called only one IObserver<T> method
What it means
The same visitor in NotificationAsyncExtensions sets _valueTask when one of its IObserver<T> methods runs; if a second callback arrives (here OnCompleted after something already set _valueTask), it throws InvalidOperationException('Accept should have called only one IObserver<T> method'). The IObserver contract for Accept allows exactly one notification dispatch, so multiple calls indicate a malformed notification.
Solutions
- Ensure the notification calls exactly one IObserver<T> method per Accept.
- Use Notification<T>.CreateOnNext/OnError/OnCompleted instead of custom implementations.
- Remove wrapper code that forwards Accept to more than one observer callback.
- Fix test mocks to model one event per notification.
Example fix
// before (custom notification dispatching twice)
public void Accept(IObserver<T> observer) { observer.OnNext(_v); observer.OnCompleted(); }
// after
public void Accept(IObserver<T> observer) => observer.OnNext(_v); Defensive patterns
Strategy: try-catch
Validate before calling
if (notification is not Notification<T>) throw new InvalidOperationException("Only library-provided Notification<T> instances are supported by AcceptAsync"); Type guard
static bool IsStandardNotification<T>(INotification<T> n) => n is Notification<T>;
Try / catch
try { await notification.AcceptAsync(asyncObserver); }
catch (InvalidOperationException ex) when (ex.Message.Contains("only one IObserver<T> method")) { /* multi-dispatch bug in notification — fix implementation */ } Prevention
- One notification == one observer callback, always
- Never forward Accept to multiple observer methods in wrappers
- Use standard Notification<T>.Create* factories
- Review custom INotification types against the visitor contract
When it happens
Trigger: Accepting an INotification<T> whose Accept (or visitor forwarding) invokes more than one observer method — e.g. OnNext followed by OnCompleted, or OnError called twice — from a custom or third-party notification implementation.
Common situations: Buggy custom notification types; double-dispatch in wrappers around AcceptAsync; test doubles that replay multiple events through one notification.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/93e780d1679d5d80.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/NotificationAsyncExtensions.cs:58
{
_asyncObserver = asyncObserver;
}
public async ValueTask Wait()
{
if (!_valueTask.HasValue)
{
throw new InvalidOperationException("Accept did not call any IObserver<T> method");
}
await _valueTask.Value.ConfigureAwait(false);
}
public void OnCompleted()
{
if (_valueTask.HasValue)
{
throw new InvalidOperationException("Accept should have called only one IObserver<T> method");
}
_valueTask = _asyncObserver.OnCompletedAsync();
}
public void OnError(Exception error)
{
if (_valueTask.HasValue)
{
throw new InvalidOperationException("Accept should have called only one IObserver<T> method");
}
_valueTask = _asyncObserver.OnErrorAsync(error);
}
public void OnNext(T value)
{
if (_valueTask.HasValue)View on GitHub (pinned to 94b5d5ab91)