Skip to content

Latest commit

 

History

History
52 lines (36 loc) · 1.71 KB

PC001.md

File metadata and controls

52 lines (36 loc) · 1.71 KB

PC001: API not supported on all platforms

Cause

You're calling an API in .NET Core or .NET Standard that throws PlatformNotSupportedException in all or some circumstances.

Rule description

The goal of this rule is assisting you in writing robust code that will work across all platforms that your code might run on.

How to fix violations

The analyzer has no way to detect whether your code is correctly guarded against PlatformNotSupportedException. The fix is to review the API documentation for which this rule was triggered and to do one of the following:

  1. Not call the API.
  2. Guard this call and suppress the specific occurrence of this rule.
  3. Not run your code on the affected platforms and suppress this rule for said platforms.

When to suppress warnings

Unless you stop calling the API entirely, you have to suppress this warning.

If you want to suppress a specific occurrence, use #pragma warning disable as shown in the following example:

#pragma warning disable PC001 // API not supported on all platforms
    var x = Console.WindowWidth;
#pragma warning restore PC001 // API not supported on all platforms

If you want to ignore certain platforms, you need to edit your project file and add a PlatformCompatIgnore property that lists all platforms you don't plan to run your code on like in the following example:

<PropertyGroup>
    <PlatformCompatIgnore>Linux;macOS</PlatformCompatIgnore>
</PropertyGroup>

The PlatformCompatIgnore property accepts the following values:

  • Linux
  • macOS
  • Windows