-
Notifications
You must be signed in to change notification settings - Fork 466
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
[CA1416] Allow child APIs attribute override assembly attribute in targeted builds of cross-platform assemblies #5023
Comments
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. |
This is an expected scenario by 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. But this is happening in runtime for targeted cross platform builds which is not expected to happen in normal applications. Ideally, all platform specific implementation should be separated from cross platform src. Though that causing code duplication some level, the API owner should choose if separation is worth doing. With the implementation of dotnet/runtime#43971 we should warn whenever child API tries to extend the parent support list. But as you can see from this issue this rule is not followed in runtime repo and in most cases we don't want to separate the code, including the Unsupported attribute inconsistency. In short, dotnet/runtime#43971 is not implemented because of this conflicting issue. 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 I think we need some way to distinguish between real platform specific and cross-platform with platform specific builds. I am thinking to add |
I have tried the approach using So i decided to use MSBuild property Further in the child APIs should not extend parent support analyzer if the violation occurs we could suggest adding this property to suppress the warning if it that was the intention or remove the child attribute violation |
Internally used
[SupportedOSPlatform]
will not raise any warnings due to build automatically adding assembly-wide[SupportedOSPlatform("...")]
for the currently build platform.Repro:
Potential solution:
SupportedOS
should behave as intersection --> supported are only OSes named on all levelsUnsupportedOS
should behave as union --> unsupported are all OSes from all levelsIn other words, narrowing the lists of supported OSes with nested attributes.
Also consider that the list of operating systems in the attributes is behaving differently from the platform guards. Example:
This inconsistency confused me quite a bit since the guards used in the code must use different list of OSes than what is used in the attributes to achieve the same. This might cause some headaches to our customers in the future.
This is a spin off from conversation in dotnet/runtime#49261, see this comment dotnet/runtime#49261 (comment)
cc: @marek-safar @terrajobst @jeffhandley @buyaa-n
The text was updated successfully, but these errors were encountered: