Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer Misalignment: [SupportedOSPlatform] on Process.Start incorrectly restricts use to maccatalyst #7497

Open
evoronkin opened this issue Dec 5, 2024 · 0 comments

Comments

@evoronkin
Copy link

Analyzer

Diagnostic ID: CA1416: Validate platform compatibility

Analyzer source

Environment Details

.NET SDK Version: 8.0.x

Target Framework: net8.0

IDE/Tooling: Visual Studio 2022 (or CLI with dotnet commands)

Platform: Windows/Linux/macOS (as applicable)

Describe the bug

Problem became visible from the introduction of this change
Support Process.Start() on MacCatalyst dotnet/runtime#61507
When using Process.Start in a project targeting net8.0, the platform compatibility analyzer (CA1416) incorrectly emits a warning that the method is only supported on maccatalyst, even though it works on Windows, Linux, and macOS. This behavior seems to misinterpret the [SupportedOSPlatform("maccatalyst")] attribute as a restriction rather than an indication of additional support.

Steps To Reproduce

  1. Create a new .NET 8 project targeting net8.0.

  2. Add code to call Process.Start, e.g.:

if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
Process.Start("your_program");
}

  1. Build the project and observe the CA1416 warning.

Reproducible Code:

using System.Diagnostics;

class Program
{
static void Main()
{
if (OperatingSystem.IsWindows() || OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
Process.Start("notepad");
}
}
}

.csproj Configuration:

net8.0 win-x64;linux-x64;osx-x64

Expected behavior

The analyzer should not emit warnings for Process.Start when:

  1. The runtime platform is explicitly checked (e.g., OperatingSystem.IsWindows()).
  2. A method guarded with [SupportedOSPlatformGuard] is used.
  3. The target framework is net8.0 with runtime identifiers for win, linux, and osx.

Actual behavior

The analyzer emits the following warning:

CA1416: This call site is reachable on all platforms. 'Process.Start(string)' is only supported on: 'maccatalyst'.

Even after:

  1. Adding explicit runtime checks (e.g., if (OperatingSystem.IsWindows()) { Process.Start(...) }).
  2. Using a SupportedOSPlatformGuard method.
  3. Ensuring correct runtime identifiers (win, linux, osx) in the project configuration.

This prevents Process.Start from being used without suppressing the warning manually.

Additional context

Additional Context

This misalignment forces developers to either suppress warnings manually or avoid using Process.Start altogether, despite its functional support across platforms. The expected behavior is for the analyzer to respect runtime checks or platform guards.

Similar Issues or Documentation:

Link to the documentation on [SupportedOSPlatform]: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformattribute

Link to the documentation on [SupportedOSPlatformGuard]: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.supportedosplatformguardattribute

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

No branches or pull requests

1 participant