# CSharp - Sections of code should not be commented out

**URL:** <https://community.sonarsource.com/t/csharp-sections-of-code-should-not-be-commented-out/70478>\
**Category:** Report False-positive / False-negative...\
**Tags:** sonarqube-cloud\
**Created:** [August 25, 2022, 8:46pm UTC](https://community.sonarsource.com/t/csharp-sections-of-code-should-not-be-commented-out/70478 "2022-08-25T20:46:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wayne](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@Wayne](https://community.sonarsource.com/u/Wayne)\
**Post date:** [August 25, 2022, 8:46pm UTC](https://community.sonarsource.com/t/csharp-sections-of-code-should-not-be-commented-out/70478/1 "2022-08-25T20:46:03Z")

</div>

- ALM used (Azure DevOps)
- CI system used (Azure DevOps)
- Languages of the repository : CSharp
- Rule : [C# static code analysis: Sections of code should not be commented out (sonarsource.com)](https://rules.sonarsource.com/csharp/RSPEC-125)

**Questions:**

- Is there any more documentation around this rule? i.e. an example of complaint vs non complaint code. This seems trivial but when it doesn’t work I start to question my understanding of ‘section’’

**Issue:**  
Commented code not being identified as a code smell. Unfortunately I am not able to share the related code but it is a method with the contents marked with ‘//’ on each line.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [August 26, 2022, 7:28am UTC](https://community.sonarsource.com/t/csharp-sections-of-code-should-not-be-commented-out/70478/2 "2022-08-26T07:28:55Z")

</div>

Hey there.

Without a reproducer, it won’t be possible to efficiently investigate the issue. I would recommend creating a reproducer that doesn’t include any sensitive code.

---

<div class="post-metadata">

**Author:** ![Wayne](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@Wayne](https://community.sonarsource.com/u/Wayne)\
**Post date:** [August 29, 2022, 8:26am UTC](https://community.sonarsource.com/t/csharp-sections-of-code-should-not-be-commented-out/70478/3 "2022-08-29T08:26:11Z")

</div>

Hi Colin,

I added this class to the codebase as an example:

```auto
public class TestCodeSmells {

    public static void CommentedOutMethodContentsUsingSingleLine(){
        //DateTime localDate = DateTime.Now;
        //String[] cultureNames = { "en-US", "en-GB", "fr-FR",
        // "de-DE", "ru-RU" };

        //foreach (var cultureName in cultureNames) {
        // var culture = new CultureInfo(cultureName);
        // Console.WriteLine("{0}: {1}", cultureName,
        // localDate.ToString(culture));
        //}
    }

    public static void CommentedOutMethodContentsUsingMulitLine(){
        /*
        DateTime dt = new DateTime(2003, 5, 1);
        Console.WriteLine("Is Thursday the day of the week for {0:d}?: {1}",
                       dt, dt.DayOfWeek == DayOfWeek.Thursday);
        Console.WriteLine("The day of the week for {0:d} is {1}.", dt, dt.DayOfWeek);
        */
    }

    /*
    public static void CommentedOutMethodUsingMultiLine(){
       System.DateTime moment = new System.DateTime(
                                1999, 1, 13, 3, 57, 32, 11);
        // Year gets 1999.
        int year = moment.Year;

        // Month gets 1 (January).
        int month = moment.Month;

        // Day gets 13.
        int day = moment.Day;

        // Hour gets 3.
        int hour = moment.Hour;

        // Minute gets 57.
        int minute = moment.Minute;

        // Second gets 32.
        int second = moment.Second;

        // Millisecond gets 11.
        int millisecond = moment.Millisecond;
    }
    */
}

```

It still never identified it as a code smell.  
Screenshot of rule being active:  
 ![ProfileWithRuleEnabled](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/b/f/bf21e2094ab72073282af1a3171041770ed89b3a.png)

Would you be able to please try the example code on your side?

---

<div class="post-metadata">

**Author:** ![costin.zaharia](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/costin.zaharia/32/62600_2.png) [@costin.zaharia](https://community.sonarsource.com/u/costin.zaharia)\
**Post date:** [September 2, 2022, 3:54pm UTC](https://community.sonarsource.com/t/csharp-sections-of-code-should-not-be-commented-out/70478/5 "2022-09-02T15:54:40Z")

</div>

Hi Wayne, thanks for reporting the issue and providing a test case.

Indeed the rule documentation is minimal and needs to be more detailed. I’ve added an issue for this: [Rule S125: improve rule documentation with examples · Issue #6062 · SonarSource/sonar-dotnet · GitHub](https://github.com/SonarSource/sonar-dotnet/issues/6062)

Regarding the code, I’ve checked it and it raised issues in both our unit tests and in the IDE. Do you use any suppressions? If not in SQ/SC maybe in [.editorconfig](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#editorconfig) or [.globalconfig](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#global-analyzerconfig).

If the rules are not suppressed. Could you please create a small reproducer project for us?

Thank you,  
Costin
