S1121: False positive for Null-conditional assignment in C# 14

  • What language is this for?
    • C#
  • Which rule?
    • csharpsquid:S1121
  • Why do you believe it’s a false-positive/false-negative?
    • It’s caused by a new C#14 feature, which allows using ?. on the left side of an assignment. It shouldn’t raise an issue, because ??= also doesn’t, which is very similar..
  • Are you using
    • SonarQube for IDE - which IDE/version?
      • Visual Studio 2026 [11206.111]
      • Version 8.30.0.15605
      • in connected mode with SonarQube Server
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
public static class Program
{
    public static void Main(string[] args)
    {
        List<int> foo = null;
        foo?.Capacity = 27;
    }
}

This reports an S1121 in the line with foo?.Capacity.

Hey there.

Agreed! It’s already in the backlog. C#14 support is coming soon.

3 Likes

Hi, thanks for the feedback.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.