[wasi] TaskToAsyncResult.Begin throws PlatformNotSupportedException

Đang mở Phù hợp với người mới
#134,955 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@lewing đang làm issue này rồi.

Từ ngày 1/11/2026.

  • #136683 của @lewing — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp

Hướng nghiên cứu

Bắt đầu tại src/libraries/Common/src/System/Threading/Tasks/TaskToAsyncResult.cs và kiểm tra điều kiện WASI trong Begin. Chạy các bài kiểm thử TaskToAsyncResultTests, bao gồm InvalidArguments_ThrowExceptions, để xác nhận wrapper APM hoạt động trên các nền tảng đơn luồng. Hoàn tất khi Begin không còn luôn thất bại trên WASI và hành vi chặn của AsyncWaitHandle vẫn được xử lý phù hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

arch-wasm area-System.Threading.Tasks os-wasi
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 https://github.com/dotnet/runtime/pull/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 https://github.com/dotnet/runtime/pull/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.

Ngôn ngữ chính
C#
Star
18.4k
Fork
5.8k
Merge trung bình
2 ngày 12 giờ
Pull request đã merge (30 ngày)
579

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/runtime

Tất cả issue của dotnet/runtime

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.