[release/7.0] Fix bugs found in MAUI repo #6405
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport #6361 into .NET 7 release branch.
Issue: .NET MAUI seeing lots of new CA1416 warnings
Description
With dotnet/runtime#68557 we added
ObsoletedOSPlatformAttribute
for annotating APIs that is Obsoleted but still works with a custom message for suggested alternative, then added support for reporting new diagnostic with custom message in PCA which introduced one of the 2 bugs that fixed. The other bug was not known edge case scenario happening when a complex guard is used for calling an API that has annotations in the parent and the child API.Customer Impact
The CA1416 Platform compatibility analyzer is included in SDK and warns by default.
The
ObsoletedOSPlatform
attribute support in Platform Compatibility Analyzer introduced the regression in .Net 7 which was not caught until xamarin team started using theObsoletedOSPlatformAttribute
in their APIs. When those bits flowed through and consumed by MAUI repo it introduces new warnings in their repo. As it was regression introduced in .NET 7 the fix better to be ported into . NET 7. The MAUI team wants the fix ported to .NET 7.0The other bug causes false positive warning when the API call was properly guarded which could happen for any customer that has a code section that reproes it.
Regression?
One of the 2 bugs that fixed is regression from .NET 6.0.
Testing
Added unit tests that reproduces the false positive warnings and manually tested the fix with MAUI repo build.
Risk
Very low. This fix will not introduce additional warning, instead it fixes/ suppresses false positive warnings