Skip to content

Annotate Windows interop declarations with [SupportedOSPlatform("windows")] - #132778

Draft
pavelsavara with Copilot wants to merge 18 commits into
mainfrom
copilot/annotate-dllimport-libraryimport-support
Draft

Annotate Windows interop declarations with [SupportedOSPlatform("windows")]#132778
pavelsavara with Copilot wants to merge 18 commits into
mainfrom
copilot/annotate-dllimport-libraryimport-support

Conversation

Copilot AI commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Annotates the platform-specific DllImport / LibraryImport / UnmanagedCallersOnly declarations under src/libraries/Common/src/Interop/Windows/** with [SupportedOSPlatform("windows")], and guards their callers.

This lets the wasm CoreCLR P/Invoke scan (PInvokeCollector) skip these declarations on browser/wasi — removing WASM0066 noise at the source — and makes them visible to CA1416 platform-compatibility analysis.

Contributes to #132776

Scope

  • Windows interop only — all 38 modules under src/libraries/Common/src/Interop/Windows/. Unix/macOS interop is not part of this change.
  • The attribute is guarded with #if NET so the shared files still compile for netstandard/netfx consumers (e.g. TestUtilities on net481), where SupportedOSPlatformAttribute does not exist.

Approach

  • Granularity. Type-level (coarse) annotation on the Interop.<Module> partial class where it is safe. Per-method annotation is used where a module's const/struct/enum members are consumed by cross-platform code — e.g. the public enums in System.Net.Primitives (SslProtocols, SocketError, …) whose values derive from Interop.SChannel.* / Interop.Winsock.* / Interop.Crypt32.* — so those members stay platform-neutral. Kernel32, Advapi32, Crypt32, BCrypt, and WinSock are per-method; the remaining modules are type-level.
  • Callers. Cross-platform files in System.Private.CoreLib reach Windows-only interop only through compile-time gates (#if TARGET_WINDOWS, #if FEATURE_COMINTEROP, *.Windows.cs, *.Nls.cs) that CA1416 cannot observe; those files carry a file-level #pragma warning disable CA1416. Managed wrapper helpers that call an annotated P/Invoke are themselves annotated [SupportedOSPlatform("windows")].

Validation

  • System.Private.CoreLib (Windows) builds clean.
  • Cross-platform consumers — System.Net.*, System.Security.Cryptography, System.Diagnostics.*, System.IO.*, System.Console, System.DirectoryServices.Protocols, and others — build clean across all target frameworks, including browser, wasi, unix, linux, osx, and android.
  • netstandard/net481 consumers of the shared interop build clean.

Note

This pull request was authored with GitHub Copilot.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
16 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI changed the title [WIP] Annotate DllImport/LibraryImport/UnmanagedCallersOnly with [SupportedOSPlatform] Research: scope [SupportedOSPlatform] annotation of interop declarations Aug 26, 2026
Copilot AI requested a review from pavelsavara August 26, 2026 13:22
@pavelsavara

This comment was marked as outdated.

…oreLib callers

Co-authored-by: pavelsavara <271576+pavelsavara@users.noreply.github.com>

This comment was marked as outdated.

@pavelsavara pavelsavara changed the title Research: scope [SupportedOSPlatform] annotation of interop declarations Annotate Windows interop declarations with [SupportedOSPlatform("windows")] Aug 27, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annotate all DllImport/LibraryImport/UnmanagedCallersOnly with [SupportedOSPlatform]

2 participants