Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change SupportedOSPlatformAttribute warning #47593

Closed
angelazhangmsft opened this issue Jan 28, 2021 · 8 comments
Closed

Change SupportedOSPlatformAttribute warning #47593

angelazhangmsft opened this issue Jan 28, 2021 · 8 comments
Assignees
Labels
area-Meta code-analyzer Marks an issue that suggests a Roslyn analyzer
Milestone

Comments

@angelazhangmsft
Copy link

angelazhangmsft commented Jan 28, 2021

Description

Windows projects OS version as SupportedOSPlatformAttribute, and the version number is computed by the minimum OS that supports that contract. When an API isn’t guaranteed to be there, a warning message (see below) points people towards authoring a version check, which is undesirable for WinRT. We should change this warning message to point people towards ApiInformation checks.

Example: If I call this code in a .NET 5 console app with SupportedOSPlatformVersion of 10.0.17763.0:

Console.WriteLine("IsDolbyVisionSupported: " + displayMonitor.IsDolbyVisionSupportedInHdrMode);

The following warning shows:

Severity Code Description Project File Line Source Suppression State Tool
Warning CA1416 This call site is reachable on: 'Windows' 10.0.17763.0 and later. 'DisplayMonitor.IsDolbyVisionSupportedInHdrMode.get' is only supported on: 'Windows' 10.0.19041.0 and later. Net5ConsoleApp C:\Users\angzhang\source\repos\Net5ConsoleApp\Net5ConsoleApp\Program.cs 23 IntelliSense Active Microsoft.CodeAnalysis.NetAnalyzers

Alternative

Alternatively, CsWinRT could remove the projection for this attribute and use the to-be-designed analyzer/attribute for contract checks.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 28, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@terrajobst terrajobst added the code-analyzer Marks an issue that suggests a Roslyn analyzer label Jan 28, 2021
@terrajobst
Copy link
Member

@jeffhandley @buyaa-n

@buyaa-n
Copy link
Contributor

buyaa-n commented Feb 26, 2021

@angelazhangmsft how could we know when it should point towards ApiInformation check? Are those APIs (or containing type/assembly) decorated with any distinguishing attribute?

@buyaa-n
Copy link
Contributor

buyaa-n commented Feb 26, 2021

Seems we can use ContractVersionAttribute is that right?

@jeffhandley
Copy link
Member

@terrajobst / @angelazhangmsft If I recall correctly on this, we concluded that this change was not necessary; is that correct?

@angelazhangmsft
Copy link
Author

Yes the current plan is to go the route of the alternative suggestion (CsWinRT could remove the projection for this attribute and use the to-be-designed analyzer/attribute for contract checks.)

@terrajobst
Copy link
Member

Yes. The conclusion was that CsWinRT should stop projecting their version information as SupportedOSPlatformAttribute and the instead provide their own analyzer.

@jeffhandley
Copy link
Member

Thank you both!

@ghost ghost locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta code-analyzer Marks an issue that suggests a Roslyn analyzer
Projects
No open projects
Development

No branches or pull requests

6 participants