Skip to content

Conversation

tmat
Copy link
Member

@tmat tmat commented May 18, 2025

When building sdk.sln from VS the following error is reported and blocks the build:

CA2025: Unawaited tasks that use 'IDisposable' instances may use those instances long after they have been disposed.

@Copilot Copilot AI review requested due to automatic review settings May 18, 2025 15:06
@tmat
Copy link
Member Author

tmat commented May 18, 2025

@baronfel

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses CA2025 by refactoring the NuGet download logic into a proper async method (so IDisposable instances are awaited) and modernizes the argument list construction using C# 12 collection expressions.

  • Moved the HttpClient download and file stream copy into an async local function and invoked it synchronously.
  • Replaced manual List<string> construction for Arguments with a C# 12 collection expression and the spread operator.

Comment on lines 50 to 58
DownloadNuGetAsync().ConfigureAwait(false).GetAwaiter().GetResult();

async Task DownloadNuGetAsync()
{
response.Content.CopyToAsync(fs).ConfigureAwait(false).GetAwaiter().GetResult();
using var client = new System.Net.Http.HttpClient();
using var response = await client.GetAsync(url).ConfigureAwait(false);
using var fs = new FileStream(nugetExePath, FileMode.CreateNew);
await response.Content.CopyToAsync(fs).ConfigureAwait(false);
}
Copy link

Copilot AI May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extracting this local async function into a private helper method could improve readability, reduce nesting, and simplify unit testing.

Copilot uses AI. Check for mistakes.

@tmat tmat enabled auto-merge (squash) May 20, 2025 01:17
@tmat tmat merged commit c67d9d9 into dotnet:main May 27, 2025
30 checks passed
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

Successfully merging this pull request may close these issues.

2 participants