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
- Null-check the continuation before calling OnCompleted
- Ensure custom awaiter implementations always provide a valid Action<object> continuation
- 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
- Prefer await over manual OnCompleted calls
- Null-check continuation arguments in custom awaiter implementations
- Use the compiler-generated await pattern to avoid null continuation bugs
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
- handler
- exception
- Not yet completed, UniTask only allow to use await.
- Already continuation registered, can not await twice or get
- Token version is not matched, can not await twice or get Sta
AI-assisted analysis of Cysharp/UniTask@ceac8d6946 (2026-08-13).
Data as JSON: /api/errors/1518183bbf563ab3.
Report an issue: GitHub.