You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The wasm CoreCLR ManagedToNativeGenerator (src/tasks/WasmAppBuilder/coreclr/PInvokeCollector.cs) already skips P/Invokes and callbacks that are unsupported on the target OS, evaluating SupportedOSPlatform / UnsupportedOSPlatform at method → declaring-type → assembly scope against the target (browser / wasi).
However, most low-level Interop.* declarations are not annotated — e.g. Interop.Kernel32.GetCurrentProcess lives in the cross-platform System.Private.CoreLib with no platform attribute. As a result they flow into the scan and produce WASM0066 noise on browser/wasi (kernel32, ntdll, advapi32, …), and more generally they are invisible to platform-compatibility tooling.
Annotating these declarations would let the existing wasm platform-skip eliminate the noise at the source, and would improve CA1416 platform-compatibility analysis across the board.
The hard part — callers
Annotating the interop leaves is not enough; the callers must be solved too.
Adding [SupportedOSPlatform("windows")] (etc.) to the low-level interop will surface CA1416 on every caller. Many callers are already guarded (if (OperatingSystem.IsWindows())) and will be fine, but some are not, and cross-cutting annotation requires walking and annotating/guarding those call chains. This is the bulk of the work and must be scoped in — it cannot be done by annotating leaves alone.
Scope
src/libraries/Common/src/Interop/** and the per-assembly interop partials.
Coordinate with the platform-compatibility analyzer (CA1416) expectations.
Enables (and is complemented by) the wasm relink-gating work in the companion issue.
Summary
Annotate platform-specific
DllImport/LibraryImport/UnmanagedCallersOnlydeclarations with[SupportedOSPlatform]/[UnsupportedOSPlatform].Motivation
The wasm CoreCLR
ManagedToNativeGenerator(src/tasks/WasmAppBuilder/coreclr/PInvokeCollector.cs) already skips P/Invokes and callbacks that are unsupported on the target OS, evaluatingSupportedOSPlatform/UnsupportedOSPlatformat method → declaring-type → assembly scope against the target (browser/wasi).However, most low-level
Interop.*declarations are not annotated — e.g.Interop.Kernel32.GetCurrentProcesslives in the cross-platformSystem.Private.CoreLibwith no platform attribute. As a result they flow into the scan and produceWASM0066noise on browser/wasi (kernel32,ntdll,advapi32, …), and more generally they are invisible to platform-compatibility tooling.Annotating these declarations would let the existing wasm platform-skip eliminate the noise at the source, and would improve CA1416 platform-compatibility analysis across the board.
The hard part — callers
Adding
[SupportedOSPlatform("windows")](etc.) to the low-level interop will surface CA1416 on every caller. Many callers are already guarded (if (OperatingSystem.IsWindows())) and will be fine, but some are not, and cross-cutting annotation requires walking and annotating/guarding those call chains. This is the bulk of the work and must be scoped in — it cannot be done by annotating leaves alone.Scope
src/libraries/Common/src/Interop/**and the per-assembly interop partials.Note
This issue was drafted with GitHub Copilot.