Skip to content
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

IDE0200 is not reported in .NET 8 but works in .NET 7 for injected dependencies #71300

Closed
arphox opened this issue Dec 18, 2023 · 1 comment · Fixed by #71324 · May be fixed by #76015
Closed

IDE0200 is not reported in .NET 8 but works in .NET 7 for injected dependencies #71300

arphox opened this issue Dec 18, 2023 · 1 comment · Fixed by #71324 · May be fixed by #76015
Labels
Area-IDE Feature - IDE0200 Remove unnecessary lambda untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@arphox
Copy link

arphox commented Dec 18, 2023

Version Used: I don't know how to check it.

I noticed that there is a difference between .NET 7 and .NET 8 in terms of what IDE0200 reports and I think it is a bug, since .NET 8 performs worse.

Steps to Reproduce:

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

editorconfig:

csharp_style_prefer_method_group_conversion = true:warning
dotnet_diagnostic.IDE0200.severity = warning

global.json – if I change version to 7.0.100, it breaks the build. But for 8.0.100 it doesn't.

{
  "sdk": {
    "version": "8.0.100",
    "rollForward": "feature"
  }
}

code:

public class Repro
{
    private readonly MethodProvider _methodProvider;

    public Repro(MethodProvider methodProvider)
    {
        _methodProvider = methodProvider;
    }

    public void Main()
    {
        int[] numbers = { 1, 2, 3, 4, 5 };
        string[] asStrings = numbers.Select(x => _methodProvider.ToStr(x)).ToArray();
        Console.WriteLine(asStrings.Length);
    }
}

public class MethodProvider
{
    public string ToStr(int x)
    {
        return x.ToString();
    }
}

Notes:

  1. I couldn't reproduce it with a simpler example where the called method would be in the same class.
  2. The list of installed SDKs on my PC: 6.0.417, 7.0.404, 8.0.100.

Diagnostic Id: IDE0200

Expected Behavior: analyzer reports

Actual Behavior: analyzer doesn't report

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 18, 2023
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature - IDE0200 Remove unnecessary lambda untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
3 participants