Title: C# S9129 not raised in SonarQube for VS Code for an Include(collection).ThenInclude(reference).ThenInclude(...) chain that a build with the same analyzers reports
Environment
- Operating system: Windows 11 x64
- IDE: VS Code Insiders 1.141
- SonarQube for IDE: 6.0.1
- Connected mode: yes, SonarQube Server 2026.5.1
- C# analyzers used by the extension:
SonarAnalyzer.CSharpandSonarAnalyzer.Enterprise.CSharp10.34.0.3385 - OmniSharp host used by the extension: 1.39.15.1-sonar (Roslyn 5.3.0)
- .NET SDK 10.0.401, EF Core 10.0.7
Problem
S9129 (“Include” and “ThenInclude” chains of reference navigations should be merged) is not raised in VS Code for a chain where a collection navigation is followed by reference navigations. The rule description lists exactly this pattern as noncompliant (“A collection navigation earlier in the chain doesn’t block merging the references that follow it”).
A normal dotnet build that loads the same two analyzer DLLs as the extension reports the issue. I confirmed by file hash that the DLLs are identical to the ones loaded in the extension’s OmniSharp process.
The analysis of the statement does run in VS Code: S8733 is reported for the same Include chain. All other findings in the file match between VS Code and the build; only S9129 is missing.
In our real project, VS Code reports 6 of the 9 S9129 issues in one file and none in another. The server analysis reports all of them.
Minimal reproducer
S9129Repro.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.7" />
</ItemGroup>
</Project>
Program.cs
using Microsoft.EntityFrameworkCore;
using var db = new ReproContext();
IQueryable<Customer> query = db.Customers;
query = query
.Include(c => c.Contracts) // S8733 (control): reported by the build and by SonarQube for VS Code
.Include(c => c.Processors)
.ThenInclude(cp => cp.Processor) // S9129: reported by the build, missing in SonarQube for VS Code
.ThenInclude(p => p.Statuses);
Console.WriteLine($"Customers: {query.Count()}");
public class ReproContext : DbContext
{
public DbSet<Customer> Customers => Set<Customer>();
protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseInMemoryDatabase("S9129");
}
public class Customer
{
public int Id { get; set; }
public ICollection<Contract> Contracts { get; set; } = [];
public ICollection<ProcessorCustomer> Processors { get; set; } = [];
}
public class Contract
{
public int Id { get; set; }
}
public class ProcessorCustomer
{
public int Id { get; set; }
public Processor Processor { get; set; } = null!;
}
public class Processor
{
public int Id { get; set; }
public ICollection<ProcessorStatus> Statuses { get; set; } = [];
}
public class ProcessorStatus
{
public int Id { get; set; }
}
Steps to reproduce
-
Put both files in a folder and run
dotnet run. It printsCustomers: 0, which also restores the packages; the extension’s OmniSharp doesn’t restore them itself. -
Open the folder in VS Code with SonarQube for IDE 6.0.1 and analyze
Program.cs. -
For comparison, build with the extension’s analyzers. Take the DLLs from its
slServices\analyzersfolder under~/.sonarlint/work, put them in a targets file, and run:
dotnet build -t:Rebuild -p:CustomAfterMicrosoftCommonTargets=<path>\probe.targets<Project> <ItemGroup> <Analyzer Include="<analyzers folder>\SonarAnalyzer.CSharp.dll" /> <Analyzer Include="<analyzers folder>\SonarAnalyzer.Enterprise.CSharp.dll" /> </ItemGroup> </Project>
Expected
S9129 on line 9 (.ThenInclude(cp => cp.Processor)), as reported by the build:
Program.cs(9,31): warning S9129: Combine this "Include" call with the "ThenInclude" call that follows it into a single "Include" call.
Actual
VS Code reports S8733 on line 7, S6966 on line 12, S927 on line 18 and S3903 on the six classes. These are all the same as the build, but S9129 on line 9 is missing.
Already ruled out
- The rule is active in the bound quality profile, and the server issues are open (not accepted or marked as false positive).
- Both analyzer DLLs are loaded in the extension’s OmniSharp process, and the project loads successfully.
- The result is the same after restarting VS Code and OmniSharp, and on two consecutive days.
- Updating VSCode and reinstalling the sonarqube extension did not change the results
- The SonarQube MCP server’s
analyze_file_list, which returns the extension’s findings directly without using the Problems view, also reports S8733 but not S9129. So the issue is not hidden by the display; the extension’s analysis does not produce it.