C# S9129 not raised in SonarQube for VS Code

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.CSharp and SonarAnalyzer.Enterprise.CSharp 10.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

  1. Put both files in a folder and run dotnet run. It prints Customers: 0, which also restores the packages; the extension’s OmniSharp doesn’t restore them itself.

  2. Open the folder in VS Code with SonarQube for IDE 6.0.1 and analyze Program.cs.

  3. For comparison, build with the extension’s analyzers. Take the DLLs from its slServices\analyzers folder 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.

Hey @dukedagmor, so just to clarify, what you’re saying is that the issue does pop up when you run a normal analysis (not an IDE-extension analysis)? I’m mostly trying to understand what do you mean by:

A normal dotnet build that loads the same two analyzer DLLs as the extension reports the issue.

Could you share a screenshot of the issue as reported on SonarQube Server?

SonarQube Server reports the issue on the real-project code that the VS Code extension misses. SonarQube for Visual Studio also reports it.

I meant a local build with the extension’s analyzer DLLs explicitly added to the compiler.

To do that, I created a temporary probe.targets file referencing the two DLLs from the extension’s slServices\analyzers folder under ~/.sonarlint/work:

<Project>
  <ItemGroup>
    <Analyzer Include="C:\path\to\analyzers\SonarAnalyzer.CSharp.dll" />
    <Analyzer Include="C:\path\to\analyzers\SonarAnalyzer.Enterprise.CSharp.dll" />
  </ItemGroup>
</Project>

I then imported that file for the build using:

dotnet build -t:Rebuild "-p:CustomAfterMicrosoftCommonTargets=C:\path\to\probe.targets"

This adds the DLLs as Roslyn analyzers for that build without requiring a permanent change to the project. Both DLLs were version 10.34.0.3385, and I verified that their file hashes matched the DLLs loaded by the extension’s OmniSharp process.

For the minimal reproducer, that build reported:

Program.cs(9,31): warning S9129: Combine this "Include" call with the "ThenInclude" call that follows it into a single "Include" call.

The VS Code extension reported S8733 on the same Include chain but did not report S9129. The purpose of this comparison was to establish that the same analyzer binaries detect the issue when run through the compiler, but miss it in the extension’s analysis.

Hey @dukedagmor, that’s a neat trick, thanks for clarifying and for sharing the steps to reproduce with such detail. I’ll flag this for the team.

Hi @dukedagmor,

Thanks for the detailed reproducer and the comparison using the same analyzer DLLs. I reproduced the issue with version 10.34.0.3385 and I think I identified the cause.

S9129 is actually generated, but Roslyn classifies it as a “non-local” diagnostic.

We will look for a fix and will keep you updated!