False positive in csharp for useless-assignment-to-local
@hvitved arbeitet bereits daran.
Seit 23.6.2026.
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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.
- Vorherrschende Sprache
- CodeQL
- Sterne
- 10.1k
- Forks
- 2.1k
- Ø Merge
- 2 T. 11 Std.
- Gemergte PRs (30 T.)
- 129
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus github/codeql
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
false-positive
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
False positive Offenfalse-positive
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 15/100