Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Plan for fixing CS0419 to include fully qualified references

  • Understand the issue: CS0419 warning message should show fully qualified names like CS0104 does
  • Locate the code that generates the warning in Binder_Crefs.cs
  • Identify that CS0104 uses SymbolDisplayFormat.CSharpErrorMessageFormat for displaying symbols
  • Create a test case that reproduces the issue from the problem statement
  • Modify the code to use FormattedSymbol with CSharpErrorMessageFormat in both locations
  • Add test for the new behavior with types in different namespaces
  • Build and test the changes - all tests pass (225 CrefTests, all CS0419 tests pass)
  • Run code review and security checks - no issues found
  • Fix WorkItem attribute to reference correct issue Include fully qualified references in CS0419 to make it less confusing #4031
  • Make test classes non-public to simplify test expectations
  • Add test for ambiguous method references with parameters (covers PerformCrefOverloadResolution path)

Summary

Successfully fixed CS0419 to display fully qualified type names in ambiguous reference warnings, matching the behavior of CS0104. The warning message now clearly shows the namespace qualification of ambiguous types and methods, making it obvious where the conflicts are coming from.

Changes Made

  1. Binder_Crefs.cs: Modified two locations where WRN_AmbiguousXMLReference is generated:

    • Line 911: ProcessParameterlessCrefMemberLookupResults - tested by AmbiguousReferenceInDifferentNamespaces
    • Line 1069: PerformCrefOverloadResolution - tested by AmbiguousReferenceInDifferentNamespaces_WithParameters
    • Both now wrap symbols with FormattedSymbol using SymbolDisplayFormat.CSharpErrorMessageFormat
  2. CrefTests.cs: Added test cases that verify the new behavior:

Example

Before:

CS0419  Ambiguous reference in cref attribute: 'TypeA'. Assuming 'TypeA', but could have also matched other overloads including 'TypeA'.

After:

CS0419  Ambiguous reference in cref attribute: 'TypeA'. Assuming 'System.Goo.TypeA', but could have also matched other overloads including 'System.TypeA'.
Original prompt

This section details on the original issue you should resolve

<issue_title>Include fully qualified references in CS0419 to make it less confusing</issue_title>
<issue_description>Given the following:

namespace System
{
    public class TypeA
    {
    }
}

namespace System.Foo
{
    public class TypeA
    {
    }
}

namespace A
{
    using System;
    using System.Foo;

    /// <summary>
    ///     <see cref="TypeA"/>
    /// </summary>
    public class Bar
    {
    }
}

You get the following:

CS0419  Ambiguous reference in cref attribute: 'TypeA'. Assuming 'TypeA', but could have also matched other overloads including 'TypeA'.

This is confusing, it should fully qualify the type to make it obvious where the two references are coming from, similar to CS0104:

CS0104  'TypeA' is an ambiguous reference between 'System.Foo.TypeA' and 'System.TypeA'

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI changed the title [WIP] Include fully qualified references in CS0419 error Fix CS0419 to display fully qualified type names for ambiguous cref symbols Nov 10, 2025
Copilot AI requested a review from CyrusNajmabadi November 10, 2025 23:51
Copilot finished work on behalf of CyrusNajmabadi November 10, 2025 23:52
Assert.Equal(SymbolKind.Property, symbol.Kind);
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/12345")]
Copy link
Member

Choose a reason for hiding this comment

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

@copilot should be #4031

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in eaef250

var source = """
namespace System
{
public class TypeA
Copy link
Member

Choose a reason for hiding this comment

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

@copilot makes these non-public, so you don't have to have the warning diagnostics about missing xml doc comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3effaa8

Copilot finished work on behalf of CyrusNajmabadi November 11, 2025 00:12
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review November 11, 2025 09:56
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner November 11, 2025 09:56
Copilot finished work on behalf of CyrusNajmabadi November 11, 2025 14:31
Copilot AI requested a review from CyrusNajmabadi November 11, 2025 14:31
@CyrusNajmabadi CyrusNajmabadi marked this pull request as draft November 11, 2025 14:44
@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review November 11, 2025 15:02
@CyrusNajmabadi
Copy link
Member

@RikkiGibson ptal.

@CyrusNajmabadi CyrusNajmabadi merged commit 8519dcf into main Nov 11, 2025
25 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Include fully qualified references in CS0419 to make it less confusing

4 participants