Skip to content

.NET 10: PlatformCompatibilityAnalyzer not working #7525

Open
@jonathanpeppers

Description

Analyzer

Diagnostic ID: CA1416: Validate platform compatibility

Analyzer source

Describe the bug

For Android, we have an API such as:

[SupportedOSPlatform("android22.0")]
public virtual int AccessibilityTraversalAfter { get; set; }

Using the API with SupportedOSPlatformVersion=21.0 does not result in a CA1416 warning.

We first noticed this here, getting the Android workload on a .NET 10 SDK:

In the following integration test:

Steps To Reproduce

  • dotnet new android
  • Use button.AccessibilityTraversalAfter
  • Observe no warnings

Here is a .binlog if that is helpful: supportedosplatformversion.zip

Expected behavior

Using the API with SupportedOSPlatformVersion=21.0 results in a CA1416 warning.

Actual behavior

Using the API with SupportedOSPlatformVersion=21.0 does not result in a CA1416 warning.

Additional context

I'm guessing the code here would not work as expected for TargetFramework=net10.0, as it has 1 more digit:

var tfmString = options.GetMSBuildPropertyValue(MSBuildPropertyOptionNames.TargetFramework, compilation);
if (tfmString?.Length >= 4 &&
tfmString.StartsWith(Net, StringComparison.OrdinalIgnoreCase) &&
int.TryParse(tfmString[3].ToString(), out var major) &&
major >= 5)

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions