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

Merged
merged 3 commits into from
Aug 14, 2025

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 Compiler Error CS0050

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@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 review from a team and adegeo August 5, 2025 13:30
Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
@BillWagner BillWagner enabled auto-merge (squash) August 14, 2025 12:29
Copy link
Contributor

PoliCheck Scan Report

The following reports lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 issues. Other issues are also a high priority. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a comment that you post to the PR. The feedback helps reduce false positive instances in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

@BillWagner BillWagner merged commit 2f9eb93 into main Aug 14, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-31062 branch August 14, 2025 12:32
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
3 participants