Skip to content

IDE0005 does not distinguish between overloaded extension methods #76974

Closed as not planned
@Muximize

Description

@Muximize

Version Used:

$ dotnet --version
9.0.102

Steps to Reproduce:

Run dotnet build on a simple project with .csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net9.0</TargetFramework>

        <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
        <WarningsAsErrors>IDE0005</WarningsAsErrors>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <NoWarn>CS1591;CS8321</NoWarn>
    </PropertyGroup>
</Project>

and Program.cs:

using System.Data;
using System.Linq;

static void Test(EnumerableRowCollection<object> target)
{
     // These two lines call the same extension method, Linq is not used.
     // But uncommenting the first line makes IDE0005 go away incorrectly

     // _ = target.Where(_ => true);
     _ = EnumerableRowCollectionExtensions.Where(target, _ => true);
}

Diagnostic Id:

IDE0005: Using directive is unnecessary.

Expected Behavior:

IDE0005 is triggered when nothing from System.Linq is used.

Actual Behavior:

using System.Linq; does not cause IDE0005 build error.

This is because the Roslyn logic in WithUsingNamespacesAndTypesBinder.cs that determines which extension methods from usings are being used does not distinguish between overloads. It only looks at the method name and arity, not the (this) parameter type.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions