-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix CA2025: Unawaited tasks that use 'IDisposable' instances ... #49040
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
Conversation
There was a problem hiding this 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 anasync
local function and invoked it synchronously. - Replaced manual
List<string>
construction forArguments
with a C# 12 collection expression and the spread operator.
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); | ||
} |
Copilot
AI
May 18, 2025
There was a problem hiding this comment.
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.
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.