dotnet/reactive · error · InvalidOperationException

Accept did not call any IObserver<T> method

Error message

Accept did not call any IObserver<T> method

What it means

This error comes from the Wait() helper on the ValueTask-based visitor that NotificationAsyncExtensions.AcceptAsync uses to apply an INotification to an async observer. If the visitor's OnNext/OnError/OnCompleted were never invoked when Wait() runs, the internal nullable ValueTask has no value and the code throws InvalidOperationException('Accept did not call any IObserver<T> method'). It is an internal invariant check: a well-formed notification always dispatches exactly one observer callback.

Solutions

  1. Fix the custom INotification<T> implementation so Accept invokes exactly one of OnNext/OnError/OnCompleted on the observer.
  2. Use only the standard library notification types (Notification<T>.CreateOnNext/OnError/OnCompleted).
  3. Update packages so notification and AsyncRx versions match.
  4. If wrapping AcceptAsync, catch InvalidOperationException as a programming-error signal.

Example fix

// before (custom notification)
public void Accept(IObserver<T> observer) { /* nothing called */ }
// after
public void Accept(IObserver<T> observer) => observer.OnNext(_value);
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("Accept did not call")) { /* notification implementation is broken — do not retry, fix the type */ }

Prevention

When it happens

Trigger: Calling AcceptAsync on an INotification<T> implementation whose Accept never calls back into the supplied IObserver<T> — e.g. a custom/broken notification type, or accepting a notification whose visitor contract was violated by a third-party implementation.

Common situations: Custom INotification implementations that forget to call the visitor; library/version mismatch where a notification type predates the visitor API; hand-rolled notification mocks in tests.

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/a5f8e61e8b3fda2e. Report an issue: GitHub.

Appendix: source

Thrown at AsyncRx.NET/System.Reactive.Async/NotificationAsyncExtensions.cs:48

            notification.Accept(adapter);
            await adapter.Wait().ConfigureAwait(false);
        }

        private class NotificationAdapter<T> : IObserver<T>
        {
            private readonly IAsyncObserver<T> _asyncObserver;
            private ValueTask? _valueTask;

            public NotificationAdapter(IAsyncObserver<T> asyncObserver)
            {
                _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)

View on GitHub (pinned to 94b5d5ab91)