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

Aperta
#22,032 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@hvitved ci sta già lavorando.

Dal 23/6/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.

Lingua principale
CodeQL
Stelle
10.1k
Fork
2.1k
Merge medio
2g 11h
PR unite (30g)
129

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/codeql

Tutte le issue di github/codeql

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.