You're calling an API in .NET Core or .NET Standard that throws
PlatformNotSupportedException
in all or some circumstances.
The goal of this rule is assisting you in writing robust code that will work across all platforms that your code might run on.
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:
- Not call the API.
- Guard this call and suppress the specific occurrence of this rule.
- Not run your code on the affected platforms and suppress this rule for said platforms.
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