Incorrect S1751 triggered by using block

I’m using SonarAnalyzer.CSharp Version 7.14.0.8411, and the following triggers a S1751 “Loops with at most one iteration should be refactored”.

It’s not really a loop, so I think it’s a false positive.

The response (HttpResponseMessage) is IDisposable, so I’ll have to dispose of it.

using (var response = await _client.PostAsync(_config.EndpointUri, payload).ConfigureAwait(false))
{
    return HandleResponse(response);
}

1 Like

thanks @HenningNT and welcome to our community forum. I’ve opened issue 2472 to track this FP

Hi @HenningNT,

I cannot reproduce this issue with the latest version. (SonarC# 7.17.0.9346).

I’ve used the following snippet to validate it:

public static async Task<bool> Using()
{
    var client = new HttpClient();
    var payload = new ByteArrayContent(new byte[0]);

    using (var response = await client.PostAsync("www.google.com", payload).ConfigureAwait(false))
    {
        return HandleResponse(response);
    }
}

private static bool HandleResponse(HttpResponseMessage message) => true;

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