Skip to content

Fix CA1416: mark IsRunningOnWindows as a platform guard#2017

Merged
matt-richardson merged 1 commit into
mainfrom
fix/ca1416-platform-guard
Jun 15, 2026
Merged

Fix CA1416: mark IsRunningOnWindows as a platform guard#2017
matt-richardson merged 1 commit into
mainfrom
fix/ca1416-platform-guard

Conversation

@matt-richardson

Copy link
Copy Markdown
Contributor

What

Adds [SupportedOSPlatformGuard("windows")] to CalamariEnvironment.IsRunningOnWindows.

Why

CA1416 (platform compatibility) fires at DockerCredentialHelper.EnsureCredentialHelperIsExecutable, where File.GetUnixFileMode/File.SetUnixFileMode (both [UnsupportedOSPlatform("windows")]) are called. That method already guards with:

if (CalamariEnvironment.IsRunningOnWindows)
    return;

…but the analyzer's flow analysis only recognises the BCL guards (OperatingSystem.IsWindows(), RuntimeInformation.IsOSPlatform, or the platform attributes), so it couldn't tell the Unix-only calls are unreachable on Windows.

SupportedOSPlatformGuardAttribute is the purpose-built way to teach the analyzer that a custom boolean member is an OS guard. It's read from metadata, so it works cross-assembly (the property lives in Calamari.Common, the call site in Calamari.Shared) and clears CA1416 anywhere the property is used as a guard — not just this one site.

Impact

  • Clears the CA1416 category (4 warnings counting both TFMs).
  • No behaviour change — purely an analyzer annotation; the property's logic is untouched.
  • Keeps the codebase-standard CalamariEnvironment.IsRunningOnWindows rather than swapping in OperatingSystem.IsWindows() at each call site.
  • Calamari.Shared builds clean.

🤖 Generated with Claude Code

Annotate CalamariEnvironment.IsRunningOnWindows with
[SupportedOSPlatformGuard("windows")] so the platform-compatibility
analyzer recognises it as an OS guard. CA1416 only understands the BCL
guards (OperatingSystem.IsWindows() etc.), so it couldn't tell that
guarded call sites (e.g. File.Get/SetUnixFileMode in
DockerCredentialHelper) are unreachable on Windows.

The attribute is read from metadata, so this works cross-assembly and
clears the warning anywhere the property is used as a guard, without
changing the property's behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@matt-richardson matt-richardson marked this pull request as ready for review June 15, 2026 05:25
@matt-richardson matt-richardson enabled auto-merge (squash) June 15, 2026 05:25
@matt-richardson matt-richardson merged commit ae9d7a9 into main Jun 15, 2026
35 checks passed
@matt-richardson matt-richardson deleted the fix/ca1416-platform-guard branch June 15, 2026 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants