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.
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
- Wrap platform-specific calls in an OS check (
OperatingSystem.IsWindows()). - Provide a cross-platform alternative for the non-Windows path.
- Or run the affected job on a matching OS runner, then re-run.
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.