Search code examples
c#visual-studiouwp

How to fix C# Warning CA1416 in UWP using Visual Studio


I have a project with min version Windows 10, version 1809 (10.0; Build 17763) and I get thousands of warnings:

This call site is reachable on all platforms. 'ValueSet.this[string]' is only supported on: 'Windows' 10.0.10240.0 and later. 

I read documentation, it suggests using:

[UnsupportedOSPlatform("windows")]
[SupportedOSPlatform("windows10.0.17763")]

I can't use it because:

CS0246: The type or namespace name 'UnsupportedOSPlatformAttribute' could not be found (are you missing a directive or an assembly reference?)
CS0246: The type or namespace name 'UnsupportedOSPlatform' could not be found (are you missing a directive or an assembly reference?)

How to fix this and why do I get a warning message if the version is higher than 10.0.10240.0?


Solution

  • I figured out, because I have multiple project with different frameworks and I share cs files between them, I can't use directly [SupportedOSPlatform("windows10.0.17763")].

    I must specify for which framework rule is:

    #if NET
            [System.Runtime.Versioning.SupportedOSPlatform("windows10.0.17763")]
    #endif