Repository navigation
Description
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/EnableBroadcasttofalseworks buttruedoesn't, andPoll/Selectwork 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_THREADSaround[UnsupportedOSPlatform("browser")]onThread.StartinSystem.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
- Track platform limitations. Add
[UnsupportedOSPlatform("wasi")]where a limitation belongs to the WASI platform and isn't expected to change, matching browser. Replace the matchingOperatingSystem.IsWasi()throws with that attribute, or keep the throws and point them at this issue. Keep runtime checks for partial or value-dependent limits. - 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 howRequiresDynamicCodeties APIs toRuntimeFeature.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. - Until (2) exists, keep single-threaded limitations as runtime checks on
!RuntimeFeature.IsMultithreadingSupported, notOperatingSystem.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.CachingdeclaresUnsupportedOSPlatformsfor 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
dotnet-policy-service commentedon Nov 15, 2026
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Nov 15, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.
Point remaining WASI PNSE guards at dotnet#137564
jkotas commentedon Nov 15, 2026
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 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.
lewing commentedon Nov 15, 2026
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.
jkotas commentedon Nov 15, 2026
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.
lewing commentedon Nov 15, 2026
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.
jkotas commentedon Nov 15, 2026
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
pavelsavara commentedon Nov 16, 2026
This is what Joel Dice advocated for when we spoke about the issues. Specifically simple CLI tools.
And I opted to only support non-blocking APIs on WASI for 3 reasons.
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
jkotas commentedon Nov 16, 2026
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.
Reword WASI HTTP stream sync-I/O comments