Skip to content

[wasi] Express WASI and single-threaded limitations through platform annotations #137564

Open

Description

@lewing

Background

Many APIs that can't work on WASI still throw PlatformNotSupportedException at run time with no compile-time signal. These include socket options, reverse DNS, Unix domain sockets, and several crypto, configuration and type-converter paths. On browser, the equivalent APIs carry [UnsupportedOSPlatform("browser")], so callers get CA1416 warnings. On WASI the same APIs typically use if (OperatingSystem.IsWasi()) throw new PlatformNotSupportedException();.

#107185 started adding [UnsupportedOSPlatform("wasi")] to the API surface but was closed without merging. Its TODO remove with #107185 comments stayed in the source until #136683, which audits them; this issue replaces them as the tracking item. #114221 (Console APIs missing [UnsupportedOSPlatform("wasi")]) is one instance of the gap.

There are two different kinds of limitation, and they need different treatment.

1. Limitations of the WASI platform itself

Examples:

  • reverse DNS (no getnameinfo)
  • AF_UNIX
  • socket options wasi-sockets doesn't expose
  • APIs in assemblies already marked unsupported on WASI (crypto, System.Net.Security, System.Configuration.ConfigurationManager)

[UnsupportedOSPlatform("wasi")] fits these, as it does for browser. Two caveats:

  • WASI is still evolving. What the host supports changes across WASI versions, proposals and runtimes. An API should be annotated where it is unlikely to become supported, not wherever it currently throws, so we don't have to churn the reference assemblies when support arrives.
  • Some limits are partial. For example, setting DontFragment/EnableBroadcast to false works but true doesn't, and Poll/Select work with a zero timeout. A member-level attribute can't express these, so they stay runtime checks.

2. Limitations of single-threaded runtimes

Examples:

  • synchronous socket/stream I/O that would block
  • Thread.Start
  • blocking waits
  • End* on an incomplete APM operation

These aren't really about the OS. They depend on whether the runtime build supports multithreading, which RuntimeFeature.IsMultithreadingSupported already reports and which applies to browser and WASI alike.

Today the only way to express them at compile time is [UnsupportedOSPlatform("browser")] / [UnsupportedOSPlatform("wasi")]. That conflates the platform with a runtime configuration:

  • It can be wrong for a multithreaded build. Supporting that configuration currently means compiling different reference assemblies, e.g. #if !FEATURE_WASM_MANAGED_THREADS around [UnsupportedOSPlatform("browser")] on Thread.Start in System.Threading.Thread/ref/System.Threading.Thread.cs.
  • Annotating the threading-related surface for WASI the same way would duplicate that pattern across more reference assemblies.

IsMultithreadingSupported is already an [UnsupportedOSPlatformGuard("browser")] / [UnsupportedOSPlatformGuard("wasi")] and a feature switch, but there's no attribute to mark an API as requiring it.

Proposal

  1. Track platform limitations. Add [UnsupportedOSPlatform("wasi")] where a limitation belongs to the WASI platform and isn't expected to change, matching browser. Replace the matching OperatingSystem.IsWasi() throws with that attribute, or keep the throws and point them at this issue. Keep runtime checks for partial or value-dependent limits.
  2. Design a runtime-feature annotation. Explore expressing "requires multithreading" as a runtime-feature requirement instead of an OS list. For example, an analyzer-recognized attribute that ties an API to RuntimeFeature.IsMultithreadingSupported, similar to how RequiresDynamicCode ties APIs to RuntimeFeature.IsDynamicCodeSupported. Callers would get a diagnostic in single-threaded configurations, existing guards would suppress it, and threaded and single-threaded builds could share one set of reference assemblies. This needs an API proposal and analyzer work (CA1416 or a new rule), so it's listed here for discussion rather than as committed scope.
  3. Until (2) exists, keep single-threaded limitations as runtime checks on !RuntimeFeature.IsMultithreadingSupported, not OperatingSystem.IsWasi(), so they follow the runtime configuration rather than the OS.

Open questions

  • Should (1) also add [UnsupportedOSPlatform("browser")] where browser has the same limitation but isn't annotated yet? (For example, System.Runtime.Caching declares UnsupportedOSPlatforms for wasi only.)
  • Is a dedicated attribute the right shape for (2), or would extending the existing analyzer to understand feature-switch-based guards be enough?

Note

This issue was drafted with GitHub Copilot.

Activity

  1. added
    arch-wasm
    os-wasi
    on Nov 15, 2026
  2. added
    untriaged
    on Nov 15, 2026
  3. dotnet-policy-service commented on Nov 15, 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 Nov 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
    See info in area-owners.md if you want to be subscribed.

  5. added this to the 12.0.0 milestone on Nov 15, 2026
  6. removed
    untriaged
    on Nov 15, 2026
  7. self-assigned this
    on Nov 15, 2026
  8. jkotas commented on Nov 15, 2026

    @jkotas
    Member

    "requires multithreading" as a runtime-feature requirement instead of an OS list

    The single-threaded vs. multithreading wasm flavors behave as distinct OSes. The runtime binaries for each flavor are different, the capabilities are different, etc. They are not represented as such currently that creates problems throughout the stack that would have to solved by adding another OS-like dimension everywhere. We should consider introducing new RIDs for the multi-threaded wasm flavors to avoid that, and then model the annotations with that in mind.

    System.Runtime.Caching

    System.Runtime.Caching is a legacy assembly that exists to ease .NET Framework -> .NET Core migrations. We do not recommend using it in any new code. Legacy assemblies like this should be marked as unsupported for wasm platforms at the assembly level. We should not be spending time on fine grained annotations for these.

  9. lewing commented on Nov 15, 2026

    @lewing
    MemberAuthor

    "requires multithreading" as a runtime-feature requirement instead of an OS list

    The single-threaded vs. multithreading wasm flavors behave as distinct OSes. The runtime binaries for each flavor are different, the capabilities are different, etc. They are not represented as such currently that creates problems throughout the stack that would have to solved by adding another OS-like dimension everywhere. We should consider introducing new RIDs for the multi-threaded wasm flavors to avoid that, and then model the annotations with that in mind.

    I understand that. The point I wanted to express here is that adding the current attributes drops that distinction where we already know it and while I'm visiting all these places I would like to add an attribute that makes the distinction clear now so "all wasi" vs "single threaded wasi". If we think of the current attribute as "single threaded wasi" then I would like to put "all wasi" on the places that are not impacted by threading so that I don't have to go back to them and add "wasimt" for those instead. But more than that I would like a single attribute that says "unsupported on single threaded" that would apply to browser and wasi in single threaded mode instead of a mix of OsPlatform attributes.

  10. jkotas commented on Nov 15, 2026

    @jkotas
    Member

    How many APIs do you expect to be in the pure unsupported on single threaded category? I would expect this list to be fairly small.

    For example, are synchronous network API going to be allowed in single-threaded wasi? I would expect them to work fine on wasi. There is no fundamental reason for blocking them there.

  11. lewing commented on Nov 15, 2026

    @lewing
    MemberAuthor

    How many APIs do you expect to be in the pure unsupported on single threaded category? I would expect this list to be fairly small.

    For example, are synchronous network API going to be allowed in single-threaded wasi? I would expect them to work fine on wasi. There is no fundamental reason for blocking them there.

    That is a bit of an open question. Single-threaded sync socket I/O could work by blocking on the socket's pollable, but blocking stops progress on everything else, which breaks in-process loopback, timers and cancellation by Dispose, and sync-over-async layers still hit Task waits. It is a bit of a mirror problem to async, once you enter a sync path the escape hatch is threads.

  12. jkotas commented on Nov 15, 2026

    @jkotas
    Member

    A lot of libraries and simple apps out there are single threaded and use synchronous I/O. It is a very popular programming model. We got a lot of feedback about that when we tried to kill synchronous networking in early days of .NET Core.

    At the same time, it is important to avoid synchronous network I/O and other kind of blocking (sync over async, long compute-bound operations) in code that needs to scale well. This concern is not specific to single threaded wasm.

    For wasi, I think it would make sense to support both programming models and allow users to choose.

    For detecting problematic blocking that works poorly with async, I would double down on general purpose analyzers (not specific to single-threaded wasm) as needed. There are some existing analyzers in this space, for example https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1849

  13. pavelsavara commented on Nov 16, 2026

    @pavelsavara
    Member

    simple apps out there are single threaded and use synchronous I/O

    This is what Joel Dice advocated for when we spoke about the issues. Specifically simple CLI tools.

    For wasi, I think it would make sense to support both programming models and allow users to choose.

    And I opted to only support non-blocking APIs on WASI for 3 reasons.

    • test and maintenance surface for us.
    • for naive dotnet developer migrating existing dektop or server app to WASI, it would compile just fine and then it would lag always synchronously waiting on the slowest I/O. We would have hard time explaining why Tasks and Timers stopped working in the meantime.
    • consistency with the browser programing model, which is the current ST standard we have. There sync blocking is also bad idea because it blocks browser internals of that tab page.

    For detecting problematic blocking ... general purpose analyzers

    Makes sense. That could also help to avoid some poor blocking APIs on non-WASI server side. I guess there are some FS and DNS opportunities in aspnetcore. Also for some of it, public BCL async API alternatives are still missing.

    my 2c

  14. jkotas commented on Nov 16, 2026

    @jkotas
    Member

    only support non-blocking APIs on WASI

    I would be fine with this too. We should be mindful that it is WASI specific limitation that may change in future. It is not a fundamental general limitation of single threaded programming models.

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.Threadingos-wasi

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions