Skip to content

Wrong CA1416 warning within members annotated with [SupportedOSPlatformGuard] #54066

@Sergio0694

Description

@Sergio0694

I just noticed that if you use [SupportedOSPlatformGuard], the normal CA1416 analyzer breaks down. Consider this snippet:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0-windows10.0.26100.0</TargetFramework>
	<SupportedOSPlatformVersion>10.0.18362.0</SupportedOSPlatformVersion>
  </PropertyGroup>
</Project>
using System.Runtime.Versioning;
using Windows.Foundation.Metadata;
using Windows.UI.Composition;

class C
{
    public void M1()
    {
        // No warning (correct)
        _ = ApiInformation.IsMethodPresent(
            typeName: typeof(CompositionEasingFunction).FullName,
            methodName: nameof(CompositionEasingFunction.CreatePowerEasingFunction));
    }

    [SupportedOSPlatformGuard("windows10.0.20348.0")]
    public bool M2() => ApiInformation.IsMethodPresent(
        typeName: typeof(CompositionEasingFunction).FullName,
        methodName: nameof(CompositionEasingFunction.CreatePowerEasingFunction)); // warning..?!?
}

This gives you this:

Image

If you add [SupportedOSPlatformGuard], the CA1416 analyzer starts firing even if the project has a higher minimum OS version.

We're having dozens of hits in the Microsoft Store (we just updated the Windows SDK to get the new annotations).

cc. @sbomer could you help take a quick look if you can? Thank you! 🙂

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions