Skip to content

Update CS0524 documentation to reflect C# 8.0 changes allowing nested types in interfaces #47669

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 4 commits into from
Aug 4, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 30, 2025

The CS0524 compiler error documentation was outdated and misleading. It stated that interfaces cannot declare types, but this restriction was lifted in C# 8.0 with the introduction of default interface members.

Changes Made

  • Updated the documentation to clarify that CS0524 is no longer generated for nested types in interfaces since C# 8.0
  • Explained that nested types are now allowed as part of the default interface members feature
  • Changed the example from showing an error case to showing valid modern C# code
  • Fixed the interface naming convention in the example (changed Clx to IExample following C# conventions)
  • Updated the ms.date field to reflect the documentation update
  • Added helpful cross-references to related documentation about interfaces, nested types, and C# version history

Before and After

Before: The documentation incorrectly stated that interfaces cannot contain user-defined types and showed an example that would generate CS0524.

After: The documentation accurately explains that this restriction was removed in C# 8.0 and provides a working example of nested types in interfaces.

The code example now compiles and runs successfully in modern C#:

// This code is valid in C# 8.0 and later
public interface IExample  
{  
    public class NestedClass   // Valid since C# 8.0
    {  
    }  
}  

Fixes #28427.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/misc/cs0524.md docs/csharp/misc/cs0524

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Jul 30, 2025
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] CS0524 is not raised. Update CS0524 documentation to reflect C# 8.0 changes allowing nested types in interfaces Jul 30, 2025
@Copilot Copilot AI requested a review from BillWagner July 30, 2025 19:04
Copilot finished work on behalf of BillWagner July 30, 2025 19:04
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.

One change, and then this is ready.

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI requested a review from BillWagner July 31, 2025 15:16
Copilot finished work on behalf of BillWagner July 31, 2025 15:16
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 now ready for final review.

@BillWagner BillWagner marked this pull request as ready for review July 31, 2025 15:22
@BillWagner BillWagner requested a review from a team as a code owner July 31, 2025 15:22
@BillWagner BillWagner requested a review from tdykstra July 31, 2025 15:22
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
@Copilot Copilot AI requested a review from gewarren August 4, 2025 18:06
Copilot finished work on behalf of gewarren August 4, 2025 18:06
@BillWagner BillWagner enabled auto-merge (squash) August 4, 2025 18:21
@BillWagner BillWagner merged commit 8df888d into main Aug 4, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-28427 branch August 4, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csharp-errors-warnings/subsvc dotnet-csharp/svc 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.

CS0524 is not raised.
3 participants