Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer fixer does not respect method arguments when choosing to Async counterpart #1422

Open
Tobbeman opened this issue Feb 22, 2025 · 0 comments

Comments

@Tobbeman
Copy link

Tobbeman commented Feb 22, 2025

Look at the diff below, created by dotnet format

         var content = await response.Content.ReadAsStringAsync();
-        AssertSuccess(response, content);
+        await AssertSuccessAsync(response, content);
         return Deserialize<BidResponsePayload>(content);

The methods in question:

    private async Task AssertSuccessAsync(HttpResponseMessage response)
    {
        AssertSuccess(response, await response.Content.ReadAsStringAsync());
    }

    private void AssertSuccess(HttpResponseMessage response, string content)
    {
        if (!response.IsSuccessStatusCode)
        {
            _logger.LogError("Failed with response: {}", content);
            throw new HttpRequestException();
        }
    }

Looks to me like the fixer sees that the code is in a async context and there is a async method of AssertSuccess available. No consideration is taken that the arguments match

Code is VSTHRD103

Version:

~/dev/checkwattapi(cleanup/dotnet-format)$ dotnet --info
.NET SDK:
 Version:           8.0.400
 Commit:            36fe6dda56
 Workload version:  8.0.400-manifests.6356aace
 MSBuild version:   17.11.3+0c8610977

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  22.04
 OS Platform: Linux
 RID:         linux-x64
 Base Path:   /home/tobbe/.dotnet/sdk/8.0.400/

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      9.0.0
  Architecture: x64
  Commit:       9d5a6a9aa4

.NET SDKs installed:
  6.0.400 [/home/tobbe/.dotnet/sdk]
  8.0.400 [/home/tobbe/.dotnet/sdk]
  9.0.100 [/home/tobbe/.dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.8 [/home/tobbe/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.8 [/home/tobbe/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.0 [/home/tobbe/.dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.8 [/home/tobbe/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.8 [/home/tobbe/.dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.0 [/home/tobbe/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  DOTNET_ROOT       [/home/tobbe/.dotnet]

global.json file:
  /home/tobbe/dev/checkwattapi/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant