False positive in csharp for useless-assignment-to-local

Ouverte
#22,032 1 commentaire 0 réactions 1 personne assignée Voir sur GitHub

@hvitved y travaille déjà.

Depuis le 23/6/2026.

Évaluation

Cette issue n'a pas encore été évaluée.

Description

false-positive

Description of the false positive

The context is the following: the variable is used inside a lambda and captured by it.

It is not clear to me what the exact cause is. I tried to create a self-contained code sample, but I was not able to trigger the false positive that way, so the sample code relies on AspNetCore, which is the context where I got the warning.

Code samples or links to source code

To reproduce, you need a project that depends on AspNetCore, which is possible with a project file like the following: Sample.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
</Project>

The following is helper code to configure a AspNetCore WebApplication:

public static class App
{
    extension(WebApplication app)
    {
        public void Configure()
        {
            string redirectPath = "/app";
            app.MapGet("/", () => Results.Redirect(redirectPath));
        }
    }
}

CodeQL complains about the redirectPath not being used. The type of the lambda passed to MapGet is Delegate. An example with self-contained code with a similar setup and the use of a Delegate type did not trigger the false positive.

Langage dominant
CodeQL
Étoiles
10.1k
Forks
2.1k
Merge moyen
2 j 11 h
PR mergées (30 j)
129

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de github/codeql

Toutes les issues de github/codeql

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.