Skip to content
Latchkey

System.PlatformNotSupportedException at runtime in CI

PlatformNotSupportedException means the code called an API that is not available on the current OS - commonly a Windows-only API (registry, certain crypto, WPF/WinForms, performance counters) executing on a Linux CI runner. The code compiled cross-platform but the API is implemented only on some platforms.

What this error means

The app or test throws System.PlatformNotSupportedException, often naming the API. It reproduces deterministically on the affected runner OS.

dotnet
System.PlatformNotSupportedException: Operation is not supported on this platform.
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name)

Common causes

A platform-specific API on the wrong OS

Windows-only functionality (registry, DPAPI, WinForms) runs on a Linux runner where it is unimplemented.

Missing platform guard

Code does not gate the platform-specific path with an OS check, so it executes everywhere.

How to fix it

Guard the platform path or run on the right OS

  1. Wrap platform-specific calls in an OS check (OperatingSystem.IsWindows()).
  2. Provide a cross-platform alternative for the non-Windows path.
  3. Or run the affected job on a matching OS runner, then re-run.
C#
if (OperatingSystem.IsWindows())
{
    UseRegistry();
}

How to prevent it

  • Use platform-guard analyzers (CA1416) to catch unguarded calls at build time.
  • Match the CI runner OS to the platform APIs the code requires.

Frequently asked questions

What causes ""PlatformNotSupportedException""?
Windows-only functionality (registry, DPAPI, WinForms) runs on a Linux runner where it is unimplemented.
How do I fix "PlatformNotSupportedException"?
Guard the platform path or run on the right OS

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card