Skip to content

Add generic type argument accessibility example to CS0050 documentation #47705

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 1, 2025

The CS0050 compiler error documentation was missing an important case where the error can occur. The issue reported that CS0050 can also be caused when a generic type's type argument has lower accessibility than the method itself.

For example, this code generates CS0050:

internal class CeisData // Internal class
{
    public string Name { get; set; }
}

public class MyClass
{
    public static ObservableCollection<CeisData> BuildCeis()   // CS0050
    {
        return new ObservableCollection<CeisData>();
    }
}

The error occurs because CeisData is internal but the method BuildCeis() is public, making the type argument less accessible than the method.

This PR adds:

  • Updated the main description to clarify that type arguments of generic types are also covered by the accessibility rule
  • A new "Another cause" section with a complete example demonstrating the generic type argument accessibility issue
  • A corrected version showing how to fix the issue by making the type argument appropriately accessible

The documentation now comprehensively covers both the original case (direct return type accessibility) and this additional case involving generic type arguments.

Fixes #31062.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/compiler-messages/cs0050.md docs/csharp/language-reference/compiler-messages/cs0050

@Copilot Copilot AI changed the title [WIP] Another cause of error Add generic type argument accessibility example to CS0050 documentation Aug 1, 2025
@Copilot Copilot AI requested a review from BillWagner August 1, 2025 19:28
Copilot finished work on behalf of BillWagner August 1, 2025 19:28
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review August 4, 2025 18:15
@BillWagner BillWagner requested a review from a team as a code owner August 4, 2025 18:15
@BillWagner BillWagner requested a review from tdykstra August 4, 2025 18:15
@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Aug 4, 2025
@BillWagner BillWagner requested a review from a team August 5, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csharp-diagnostics/subsvc dotnet-csharp/svc lang-reference/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Another cause of error
2 participants