C# rule "Empty collections should not be accessed or iterated" should ignore TryAdd()


(Bogus) #1
  • versions used (SonarQube 7.4, Scanner: MSBuild Scanner, Language C#)
  • error observed: Empty Collection is accessed with TryAdd, but the above warning is given.
  • steps to reproduce: Use TryAdd on an empty collection in C#
  • potential workaround: none

“Empty collections should not be accessed or iterated.”
This error is erroneously shown when you use TryAdd() and not Add().

There should probably be another rule for using TryAdd(), TryParse() etc. and not checking the results.