dotnet/reactive · error · ArgumentNullException
Value cannot be null. (Parameter 'observer')
Error message
Value cannot be null. (Parameter 'observer')
What it means
This ArgumentNullException comes from AsyncObserver.FromAsyncPattern<TResult>(observer, begin, end) when the 'observer' parameter (IAsyncObserver<TResult> that receives the result or error) is null. This overload pushes the APM completion into an observer, so a null observer would make results undeliverable and is rejected immediately.
Solutions
- Pass the actual IAsyncObserver<TResult> instance you received (e.g. the one handed to your Subscribe/Run method).
- Verify the variable holding the observer is assigned before calling FromAsyncPattern.
- If the observer is optional in your design, guard with a null check and fail with a descriptive error.
Example fix
// before AsyncObserver.FromAsyncPattern<int>(null, cb => svc.BeginOp(cb, null), ar => svc.EndOp(ar)); // after IAsyncObserver<int> observer = GetObserver(); // must be non-null AsyncObserver.FromAsyncPattern(observer, cb => svc.BeginOp(cb, null), ar => svc.EndOp(ar));
Defensive patterns
Strategy: validation
Validate before calling
if (observer is null) throw new ArgumentNullException(nameof(observer));
if (begin is null || end is null) throw new ArgumentException("begin/end required");
AsyncObserver.FromAsyncPattern(observer, begin, end); Type guard
static bool IsValidObserverPattern<TResult>(IAsyncObserver<TResult> observer,
Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)
=> observer is not null && begin is not null && end is not null; Try / catch
try { AsyncObserver.FromAsyncPattern(observer, begin, end); }
catch (ArgumentNullException ex) when (ex.ParamName == "observer")
{
// observer pipeline produced null; inspect upstream Subscribe wiring
} Prevention
- Always pass the observer instance received from the Subscribe/Run callback, never a recomputed one.
- Null-check the observer at the top of custom operator implementations.
- Avoid service-locator lookups that can return null for observers.
- Add Debug.Assert(observer != null) in operator internals during development.
When it happens
Trigger: Calling AsyncObserver.FromAsyncPattern<TResult>(null, begin, end) — typically when wiring an observer from a pipeline that supplied null.
Common situations: Building custom async observables where the observer comes from SubscribeSafe/lambda plumbing that returned null; ordering mistakes when refactoring operator internals.
Related errors
- Value cannot be null. (Parameter 'onErrorAsync')
- Value cannot be null. (Parameter 'onCompletedAsync')
- Value cannot be null. (Parameter 'error')
- ArgumentNullException
- Value cannot be null. (Parameter 'onCompletedAsync')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/1eab5dcc0cf0ee4e.
Report an issue: GitHub.
Appendix: source
Thrown at AsyncRx.NET/System.Reactive.Async/Linq/Operators/FromAsyncPattern.Generated.cs:740
AsyncObserver.FromAsyncPattern(subject, begin, end, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14);
}
catch (Exception ex)
{
return Throw<Unit>(ex);
}
return subject.AsAsyncObservable();
};
}
}
public partial class AsyncObserver
{
public static IAsyncResult FromAsyncPattern<TResult>(IAsyncObserver<TResult> observer, Func<AsyncCallback, object, IAsyncResult> begin, Func<IAsyncResult, TResult> end)
{
if (observer == null)
throw new ArgumentNullException(nameof(observer));
if (begin == null)
throw new ArgumentNullException(nameof(begin));
if (end == null)
throw new ArgumentNullException(nameof(end));
return begin(async iar =>
{
TResult result;
try
{
result = end(iar);
}
catch (Exception ex)
{
await observer.OnErrorAsync(ex).ConfigureAwait(false);
return;
}View on GitHub (pinned to 94b5d5ab91)