Cysharp/UniTask · error · ArgumentNullException
observer
Error message
observer
What it means
Thrown by AsyncSubject<T>.Subscribe(IObserver<T>) (line 457) when the observer argument is null. Reactive Extensions require a non-null observer for every subscription, so UniTask enforces it with ArgumentNullException("observer"). This Subscribe is what runs when a caller subscribes to the observable produced by ToObservable().
Source
Thrown at src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskObservableExtensions.cs:457
old.OnError(error);
}
public void OnNext(T value)
{
lock (observerLock)
{
ThrowIfDisposed();
if (isStopped) return;
this.hasValue = true;
this.lastValue = value;
}
}
public IDisposable Subscribe(IObserver<T> observer)
{
if (observer == null) throw new ArgumentNullException("observer");
var ex = default(Exception);
var v = default(T);
var hv = false;
lock (observerLock)
{
ThrowIfDisposed();
if (!isStopped)
{
var listObserver = outObserver as ListObserver<T>;
if (listObserver != null)
{
outObserver = listObserver.Add(observer);
}
else
{
var current = outObserver;View on GitHub (pinned to ceac8d6946)
Solutions
- Pass a non-null IObserver<T> (or valid OnNext/OnError handler lambdas).
- If you only want the value, use observable.ToUniTask() instead of a raw observer.
- Null-check the observer before calling Subscribe.
Example fix
// before observable.Subscribe(null); // throws ArgumentNullException // after observable.Subscribe(x => Handle(x), ex => Log(ex)); // or simply: var value = await observable.ToUniTask();
Defensive patterns
Strategy: validation
Validate before calling
if (observer == null) throw new ArgumentNullException(nameof(observer)); observable.Subscribe(observer);
Prevention
- Always supply explicit OnNext/OnError handler lambdas rather than relying on optional args.
- Prefer the UniTask bridge (.ToUniTask()) when you do not need a long-lived observer.
- Null-check observer variables produced by factories before subscribing.
When it happens
Trigger: Calling .Subscribe(null) on the observable returned by ToObservable(), or passing an observer variable/expression that evaluated to null (a failed factory, a null-coalescing that returned null, or an accidental null lambda).
Common situations: Passing null in place of an observer; relying on an optional OnNext argument that defaulted to null; a Subscribe overload where the wrong slot was left null.
Related errors
- error
- Disposable is already set
- AsyncSubject is not completed yet
- Can not trigger itself in iterating.
- handler
AI-assisted analysis of Cysharp/UniTask@ceac8d6946 (2026-08-13).
Data as JSON: /api/errors/358c095a9e8a277a.
Report an issue: GitHub.