Unused using not detected for a corner case

  • Operating system: Win11 Pro 22H2
  • SonarLint plugin version: SonarLint v7.0.0.74072, VS 2022 Professional v17.6.5
  • Programming language you’re coding in: C#
  • Is connected mode used: No

Description of the problem:
The S1128 rule (unnecessary using) is not detecting unused using of namespace A, if the code uses a field/property inherited from the type typeA (belonging to namespace A) by using typeB (defined in another namespace) that inhertis from typeA

Sample screenshots:

Base class:

Class inheriting from the base one:

Class with unused using failure, example where unused using is detected (usage of Id field from the base class commented):

When usage of Id field from the base class is uncommented, then the S1128 is no longer detected, but it is still being picked up by IDE0005 (only works when file editor is opened, but not during the build time)

Kind Regards
Paweł Tichoniuk

Hello @paweltichoniuk,

Thank you for your feedback.

I can confirm this as a false negative.

A ticket has been created to fix this false negative in the sonar-dotnet repository on GitHub.

Have a nice day,