- Operating system: Windows 11 Pro
- SonarQube for VS Code plugin version: 6.1.1
- Programming language you’re coding in: C#
- Is connected mode used: Not connected
I found this issue first using the extension in Visual Studio 2026 in a large project, using SonarQube Extension 11.1.1.17449.
To narrow things down, I’ve created a fresh new C# console app in VS2026, and also I move to VS CODE, installed SonarQube extension 6.1.1, which also is having the same issue, now I am opening this ticket.
The C# application is very simple, but neither Visual Studio Extension in VS 2017, VS 2026 or Visual Studio Code Extension detect this null dereference.
using System;
namespace ConsoleApp1
{
static class Program
{
static void Main(string[] args)
{
NullDereference();
DuplicateCondition(20);
}
static void NullDereference()
{
// comments warnings are ok ✅
// var a = 1;
object obj = null; // !!
// S2259 Null dereference of obj not working ??? ⚠️
Console.WriteLine(obj.ToString());
}
static void DuplicateCondition(int value)
{
if (value > 10)
{
Console.WriteLine("A");
}
else if (value > 10) // other SonarQube rules working ✅
{
Console.WriteLine("B");
}
}
}
}
On the other hand, in our main and largest project, we run SonarQube code analysis on-premises every week. The server-side analysis reported a null dereference in code similar to the example below, but the same issue is not being detected by the IDE extension:
List<MyDTO> myList = null;
(...)
if (myVariable <= 5)
{
(...)
// ✅ works in SonarQube server
// S2259: Null pointers should not be dereferencedcsharpsquid:S2259
myList.Add(myDto);
(...)
}
Maybe it is related not with the extensions, but with the rules they have active. I have tried to make the S2259 active in the extension settings.json, but jave no success.