CA1416 Add 'CrossPlatform' as special case allowing override parent support #5094
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.
Fixes #5023
Allow child APIs attribute override assembly attribute in targeted builds of cross-platform assemblies
By the design, child APIs should not extend parent support. SupportedOSPlatform illustrates that the API/assembly only reachable for that platform and it should not have any API supported on other platforms inside it. We have planned to warn if it happens by dotnet/runtime#43971, but this scenario is happening in runtime for targeted cross-platform builds. Ideally, all platform-specific implementation should be separated from cross-platform src. Though that causing code duplication at some level, so most developers would not like to apply strict separation of code.
Even though it is an expected scenario by design it is unfortunate to not get any warning about this inconsistency or possible reference of incompatible APIs within the same assembly
After some discussion, we decided to add a special case
[SupportedOSPlatform("CrossPlatofrm")]
attribute for targeted builds of cross-platform assembly to allow child member attributes to override the parent. To distinguish between real platform-specific build and cross-platform with platform-specific builds. (We might change"CrossPlatofrm"
into"Neutral"
or something like that)CC @jeffhandley @terrajobst