S1128 false-positive when obsolete attribute is used

  • What language is this for? C#
  • Which rule? S1128
  • Why do you believe it’s a false-positive/false-negative? false-positive
  • Are you using
    • SonarQube Cloud? No
    • SonarQube Server / Community Build - which version? v25.1.0.102122
    • SonarQube for IDE - which IDE/version? VS 2022
      • in connected mode with SonarQube Server / Community Build or SonarQube Cloud? SonarQube Community Build
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

Obsolete attribute requires ‘using System;’ but it is marked as unnecessary in the analysis

using System; // S1128 raised here

namespace TestNameSpace
{
    public class TestClass
    {
        #if !NET48
            [Obsolete("Obsolete message")] // requires using System;
        #endif
        public IEnumerable<T> GetList<T>()
        {
            // implementation
        }
    }
}

I think the title is misleading; it is not about the [Obsolete] attribute but the #if pragma. That aside it is a FP indeed.

Hello @haraman21,

Welcome to the community!

I was not able to reproduce the issue locally.

Where is the issue showing up? Is it in your IDE (through SonarQube IDE) or in your SonarQube?
Can you tell me which version of your SonarQube IDE and the version of the C# analyzer you are using?
You can find the C# analyzer version in the logs when running the begin step of the SonarScanner for .NET. It should look like something like this:

Processing plugin: csharp version X.X.X.XXXX

If you are able to give me the source (including the csproj) of a very small project that reproduce the issue, it would be really helpful :pray:

Thank you,