Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 14, 2025

Enhanced the CS0119 compiler error documentation to address user feedback about uninstructive error messages when working with collections of types.

Problem

Users encountering CS0119 when trying to create List<Type> collections found the existing documentation too generic and unhelpful. The original issue described a scenario where a developer attempted:

List<Type> pageTypesList = new List<Type>();
pageTypesList.Add(Page_BaseClass); // CS0119 error

The existing documentation only provided a generic example about method/class naming conflicts, leaving developers without clear guidance on how to properly work with type collections.

Solution

Added a comprehensive Example 2 that specifically demonstrates:

  1. The Problem: Shows the exact error scenario when trying to add class names directly to List<Type>
  2. Primary Solution: Demonstrates correct usage with the typeof() operator
  3. Alternative Approach: Provides an additional method for dynamic type loading using Type.GetType()

The new example includes:

  • Complete, compilable code samples
  • Clear error explanations with inline comments
  • Proper using statements and modern C# conventions
  • Cross-references to relevant API documentation

Impact

Developers encountering CS0119 in this common scenario will now have:

  • Clear understanding of why the error occurs
  • Multiple concrete solutions to resolve it
  • Guidance on both compile-time and runtime type collection patterns

Fixes #26433.


💬 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/misc/cs0119.md docs/csharp/misc/cs0119

Copilot AI changed the title [WIP] A class name was used instead of an instance name... Improve CS0119 error documentation with specific guidance for Type collections Jul 14, 2025
Copilot AI requested a review from BillWagner July 14, 2025 19:19
Copilot finished work on behalf of BillWagner July 14, 2025 19:19
@dotnet-policy-service dotnet-policy-service bot added dotnet-csharp/svc csharp-errors-warnings/subsvc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. labels Jul 14, 2025
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 LGTM as well.

@BillWagner BillWagner marked this pull request as ready for review July 15, 2025 14:58
@BillWagner BillWagner requested a review from a team as a code owner July 15, 2025 14:58
@BillWagner BillWagner requested a review from IEvangelist July 15, 2025 14:58
@IEvangelist IEvangelist merged commit 9fa88f9 into main Jul 15, 2025
16 checks passed
@IEvangelist IEvangelist deleted the copilot/fix-26433 branch July 15, 2025 17:03
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.

A class name was used instead of an instance name...

3 participants