Cysharp/UniTask · error · ArgumentNullException

continuation

Error message

continuation

What it means

Thrown by UniTaskCompletionSourceCore<TResult>.OnCompleted when the continuation argument is null. The method registers a callback to invoke when the operation completes; a null callback would cause a NullReferenceException at completion time. The guard is a standard null-argument check at the registration boundary.

Source

Thrown at src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs:263

                }

                throw new InvalidOperationException("Critical: invalid exception type was held.");
            }

            return result;
        }

        /// <summary>Schedules the continuation action for this operation.</summary>
        /// <param name="continuation">The continuation to invoke when the operation has completed.</param>
        /// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
        /// <param name="token">Opaque value that was provided to the <see cref="UniTask"/>'s constructor.</param>
        [DebuggerHidden]
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void OnCompleted(Action<object> continuation, object state, short token /*, ValueTaskSourceOnCompletedFlags flags */)
        {
            if (continuation == null)
            {
                throw new ArgumentNullException(nameof(continuation));
            }
            ValidateToken(token);

            /* no use ValueTaskSourceOnCOmpletedFlags, always no capture ExecutionContext and SynchronizationContext. */

            /*
                PatternA: GetStatus=Pending => OnCompleted => TrySet*** => GetResult
                PatternB: TrySet*** => GetStatus=!Pending => GetResult
                PatternC: GetStatus=Pending => TrySet/OnCompleted(race condition) => GetResult
                C.1: win OnCompleted -> TrySet invoke saved continuation
                C.2: win TrySet -> should invoke continuation here.
            */

            // not set continuation yet.
            object oldContinuation = this.continuation;
            if (oldContinuation == null)
            {
                continuationState = state;

View on GitHub (pinned to ceac8d6946)

Solutions

  1. Null-check the continuation before calling OnCompleted
  2. Ensure custom awaiter implementations always provide a valid Action<object> continuation
  3. If you use the await keyword, the compiler generates the continuation for you — avoid manual OnCompleted calls

Example fix

// before
source.OnCompleted(null, state, token); // throws

// after
source.OnCompleted(myContinuation ?? (_ => { }), state, token);
Defensive patterns

Strategy: validation

Validate before calling

if (continuation != null)
{
    source.OnCompleted(continuation, state, token);
}

Prevention

When it happens

Trigger: Calling OnCompleted(null, state, token) on a UniTaskCompletionSourceCore. This typically happens when manually wiring continuations or in custom IUniTaskSource adapters that pass through a null continuation.

Common situations: Custom awaiter or IUniTaskSource implementations that forward a continuation parameter that may be null. Interop layers between UniTask and other async patterns that fail to provide a continuation.

Related errors


AI-assisted analysis of Cysharp/UniTask@ceac8d6946 (2026-08-13). Data as JSON: /api/errors/1518183bbf563ab3. Report an issue: GitHub.