Annotate Windows interop declarations with [SupportedOSPlatform("windows")] - #132778
Draft
pavelsavara with Copilot wants to merge 18 commits into
Draft
Annotate Windows interop declarations with [SupportedOSPlatform("windows")]#132778pavelsavara with Copilot wants to merge 18 commits into
pavelsavara with Copilot wants to merge 18 commits into
Conversation
|
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
This comment was marked as outdated.
This comment was marked as outdated.
…oreLib callers Co-authored-by: pavelsavara <271576+pavelsavara@users.noreply.github.com>
This comment was marked as outdated.
This comment was marked as outdated.
…form] across modules
…d cross-platform)
…m] (coarse; method-level for WinSock)
… + guard GetRandomBytes
…-platform) + guard CoreLib callers
…-platform) + guard CoreLib callers
…(wraps windows-only GetConsoleMode)
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
…EventLog, NameResolution)
…/ [SupportedOSPlatform]
…ead of scoped pragmas
This was referenced Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Annotates the platform-specific
DllImport/LibraryImport/UnmanagedCallersOnlydeclarations undersrc/libraries/Common/src/Interop/Windows/**with[SupportedOSPlatform("windows")], and guards their callers.This lets the wasm CoreCLR P/Invoke scan (
PInvokeCollector) skip these declarations onbrowser/wasi— removingWASM0066noise at the source — and makes them visible to CA1416 platform-compatibility analysis.Contributes to #132776
Scope
src/libraries/Common/src/Interop/Windows/. Unix/macOS interop is not part of this change.#if NETso the shared files still compile fornetstandard/netfxconsumers (e.g.TestUtilitiesonnet481), whereSupportedOSPlatformAttributedoes not exist.Approach
Interop.<Module>partial class where it is safe. Per-method annotation is used where a module'sconst/struct/enummembers are consumed by cross-platform code — e.g. the public enums inSystem.Net.Primitives(SslProtocols,SocketError, …) whose values derive fromInterop.SChannel.*/Interop.Winsock.*/Interop.Crypt32.*— so those members stay platform-neutral.Kernel32,Advapi32,Crypt32,BCrypt, andWinSockare per-method; the remaining modules are type-level.System.Private.CoreLibreach 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.System.Net.*,System.Security.Cryptography,System.Diagnostics.*,System.IO.*,System.Console,System.DirectoryServices.Protocols, and others — build clean across all target frameworks, includingbrowser,wasi,unix,linux,osx, andandroid.netstandard/net481consumers of the shared interop build clean.Note
This pull request was authored with GitHub Copilot.