-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
XML doc comments do not respect accessibility today when referring to symbols in assemblies. Instead they act as if they have [InternalsVisibleTo]
any assembly. This is behavior that goes back to C# 1.0 but it is becoming a problem in today's ecosystem where there is an increasing amount of shared code between assemblies and source generators that produce types with identical FQN. When this happens XML doc comment references to such types become ambiguous and the only resolution available to customers is extern alias's.
A real world example of this problem is winforms PR 10320. In this case the CSWin32 generator is used in two assemblies: System.Drawing.Common and System.Windows.Forms.Primitives. The consuming assembly has IVT for one but not the other. That means uses of the types in code is fine because the compiler only considers the assembly with IVT. Yet the exact same references in XML doc comments are ambiguous because they have effectively IVT to both assemblies.
This feels like a problem that we're going to hit more and more as source generators and shared code increase in popularity. Starting in .NET 9 I think we need to consider changing XML doc comments to respect accessibility when using language version 13.0 or higher. That is a breaking change and it's likely to impact a non-trivial number of customers as this is behavior that goes back to C# 1.0. To mitigate we should introduce a feature flag to control this behavior: XmlDocLegacyVisibility
. When set to true
or language version is 12 or earlier the compiler will exhibit the existing behavior, otherwise it will use normal accessibility when considering external symbols.
Note: no change is being proposed for XML doc accessibility to symbols in the same assembly. Those will continue to have unrestricted access.
Issues for context: