Skip to content

[wasi] TaskToAsyncResult.Begin throws PlatformNotSupportedException #134955

Closed

Description

@lewing

Description

System.Threading.Tasks.TaskToAsyncResult.Begin unconditionally throws PlatformNotSupportedException on WASI:

// src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs
public static IAsyncResult Begin(Task task, AsyncCallback? callback, object? state)
{
#if NET
    if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException(); // TODO remove with https://github.com/dotnet/runtime/pull/107185

The TODO points at #107185, a draft that added UnsupportedOSPlatform annotations for WASI; it was closed without merging. So the check remains and nothing tracks it.

Begin wraps a Task in an IAsyncResult and schedules the callback as a continuation. That does not need extra threads, although code that blocks on the returned AsyncWaitHandle would.

The APM helpers throughout the libraries go through it, so on WASI every Begin*/End* pattern built on TaskToAsyncResult fails, as does Task.Factory.FromAsync over such a pair. In the CoreCLR WASI library test runs on #134813, all six TaskToAsyncResultTests tests that run on a single-threaded platform fail this way. That includes InvalidArguments_ThrowExceptions, which expects ArgumentNullException.

Proposed fix

Remove the WASI check so Begin works as on browser. If blocking on AsyncWaitHandle must stay unsupported, keep that limitation where the wait happens. Otherwise, annotate the API as unsupported on WASI instead of throwing unconditionally.

Note

This issue was drafted with the help of GitHub Copilot.

Activity

  1. added
    arch-wasm
    os-wasi
    on Sep 30, 2026
  2. added this to the 12.0.0 milestone on Sep 30, 2026
  3. dotnet-policy-service commented on Sep 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  4. dotnet-policy-service commented on Sep 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-threading-tasks
    See info in area-owners.md if you want to be subscribed.

  5. added
    disabled-test
    on Oct 5, 2026
  6. self-assigned this
    on Nov 1, 2026
  7. added 2 commits that reference this issue on Nov 13, 2026
    076df93
    086b2b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

arch-wasmarea-System.Threading.Tasksdisabled-testos-wasi

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions