dotnet/wpf · error · NotSupportedException

new NotSupportedException()

Error message

new NotSupportedException()

What it means

DispatcherOperationWait throws NotSupportedException when the given Task's AsyncState is not a DispatcherOperationTaskMapping — i.e. the Task did not originate from a DispatcherOperation. The extension method only supports waiting on Tasks created from dispatcher operations; passing any other Task hits this sentinel error.

Solutions

  1. Only call DispatcherOperationWait on Task objects whose AsyncState is a DispatcherOperationTaskMapping (i.e. tasks created from DispatcherOperation)
  2. Check the AsyncState type before calling and use Task.Wait/await for ordinary tasks
  3. Catch NotSupportedException and fall back to standard task waiting
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Presentation/System/Windows/Threading/TaskExtensions.cs:40 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/1e7b96f8e202558a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Presentation/System/Windows/Threading/TaskExtensions.cs:40

        {
            return DispatcherOperationWait(@this, TimeSpan.FromMilliseconds(-1));
        }

        /// <summary>
        ///     Waits for the underlying DispatcherOperation to complete.
        /// </summary>
        public static DispatcherOperationStatus DispatcherOperationWait(this Task @this, TimeSpan timeout)
        {
            var mapping = @this.AsyncState as DispatcherOperationTaskMapping;
            if(mapping != null)
            {
                // This task did come from a DispatcherOperation.
                return mapping.Operation.Wait(timeout);
            }
            else
            {
                // This task did not come from a DispatcherOperation.
                throw new NotSupportedException();
            }
        }
    }
}

View on GitHub (pinned to 81131a70a4)