简体   繁体   中英

Fix false(?) warning CA1416: This call site is reachable on all platforms

Why does my code produce the warning "CA1416: This call site is reachable on all platforms. '...' is only supported on: 'windows'? In the method called, there are no windows specific calls at all (indeed, there are only simple arithmetic statements):

public static int Mod(this int k, int n) { return (k %= n) < 0 ? k + n : k; }

dividend.Mod(divisor)  //underlined with warning CA1416

I found the root cause of the problem. Just in case anyone else runs into it: In the.csproj file, there was no reference to windows; however, the project had an AssemblyInfo.cs included. This contained the line:

[assembly: SupportedOSPlatform("windows")]

I assume this was because of some old references that were not necessary any more.

i think you should check your.csproj of your project. in this case of 2 différente projects the warning msg appear.

solution: TargetFramework must be The Same.

proj1.csproj
<PropertyGroup>
        <TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>

proj2.csproj
    <PropertyGroup>
            <TargetFramework>net6.0</TargetFramework>
    </PropertyGroup>

TargetFramework must be The Same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM