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

Abierto
#22,032 1 comentario 0 reacciones 1 asignado Ver en GitHub

@hvitved ya está trabajando en esto.

Desde el 23/6/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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.

Lenguaje dominante
CodeQL
Estrellas
10.1k
Forks
2.1k
Merge medio
2 d 11 h
PR fusionados (30 d)
129

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/codeql

Todos los issues de github/codeql

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.