Skip to content

CA1416 (PlatformCompatibilityAnalyzer) false positive #6189

@Youssef1313

Description

@Youssef1313

Analyzer

Diagnostic ID: CA1416

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.NetAnalyzers

Version: 7.0.0-preview1.22403.2

Describe the bug

CheckSystemVersion calls are not taken into account.

Steps To Reproduce

Sorry, not a complete minimal repro, but I hope the idea is clear. CheckSystemVersion calls are not taken into account.

		private static (UIWindow[] Windows, CGRect StatusBarFrame) GetWindowsAndStatusBarFrame()
		{
			if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
			{
				IEnumerable<UIScene> scenes = UIApplication.SharedApplication.ConnectedScenes;
				var currentScene = scenes.FirstOrDefault(n => n.ActivationState == UISceneActivationState.ForegroundActive);

				if (currentScene is not UIWindowScene uiWindowScene)
					throw new InvalidOperationException("Unable to find current window scene.");

				if (uiWindowScene.StatusBarManager is not { } statusBarManager)
					throw new InvalidOperationException("Unable to find a status bar manager.");

				return (uiWindowScene.Windows, statusBarManager.StatusBarFrame);
			}
			else
			{
				return (UIApplication.SharedApplication.Windows, UIApplication.SharedApplication.StatusBarFrame);
			}
		}

Expected behavior

No warnings.

Actual behavior

Error CA1416: This call site is reachable on: 'MacCatalyst' 15.4 and later. 'UIApplication.StatusBarFrame.get' is unsupported on: 'maccatalyst' 13.0.0 and later.
Error CA1416: This call site is reachable on: 'MacCatalyst' 15.4 and later. 'UIApplication.Windows.get' is unsupported on: 'maccatalyst' 15.0.0 and later.

Additional context

Metadata

Metadata

Assignees

Labels

Area-Microsoft.CodeAnalysis.NetAnalyzersBugThe product is not behaving according to its current intended designFalse_PositiveA diagnostic is reported for non-problematic casehelp wantedThe issue is up-for-grabs, and can be claimed by commenting

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions