RSPEC-3267 wrongly triggering on IAsyncEnumerable

We do have some false positive of C# static code analysis on following code using IAsyncEnumerable:

public IAsyncEnumerable<Foo> GetFoos() {…}


public async Task Compute()
{
   var foos = GetFoos();
   await foreach(var foo in foos)
   {
      if (foo == …)  // violation RSPEC-3267
      {
      }
   }
}

Reason:
There are no LINQ expressions for IAsyncEnumerables, so you cannot fix this violation. There is some System.Linq.Async Nuget package which could be introduced to do this, however, this is 3 years old and seems unmaintained, so not a real solution.
Therefore we think this rule should not trigger for IAsyncEnumerables. Also you are forced to use “await foreach” for such enumerables anyway.

System:
SonarQube Server Enterprise 2025.1

Hi,

I think you may be hitting this:

Does that seem right?

 
Thx,
Ann

I don’t know, seems like I have no access permissions to your JIRA entry.

Doh!

I forgot that project is private. :frowning:

I think a screenshot is easiest:

 
Ann

We are not 100% sure if this is the same issue as JIRA issue NET-1255. But yes, it might be this one. IAsyncEnumerable is also iterable, but does not implement IEnumerable.

Hi,

Since you’re not sure, I’ve flagged this for the language experts to take a look at.

 
Ann

Hello @rkg,

System.Linq.Async will be incorporated in .NET 10, you can have more info about this here: Breaking change - System.Linq.AsyncEnumerable in .NET 10 - .NET | Microsoft Learn

Based on this article, it seems that the package has Microsoft trust to achieve LINQ expression for IAsyncEnumerables. So I would advise to use it to fix the violation.

If you plan to upgrade your project to .NET 10, you could also already use the preview of the package that will be part of .NET 10: NuGet Gallery | System.Linq.AsyncEnumerable 10.0.0-preview.3.25171.5

I will update the rule description to suggest to use System.Linq.Async package when targeting framework prior to .NET 10.

I hope this work for you.

Have a nice day.

1 Like

Thank you @sebastien.marichal! We didn’t know about the upcoming integration into .net 10 of the package. In that case this is fine for us.

2 Likes

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