Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 12, 2025

This PR fixes the SYSLIB0014 obsolete warning in DownloadedCache.cs by replacing the deprecated WebClient with HttpClient.

Problem:
The code was using the obsolete WebClient.DownloadFile() method which generates this warning:

warning SYSLIB0014: 'WebClient.WebClient()' is obsolete: 'WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.'

Solution:

  • Replaced new System.Net.WebClient().DownloadFile(url, filename) with HttpClient implementation
  • Added a static HttpClient instance for performance and proper resource management
  • Used .GetAwaiter().GetResult() to maintain the existing synchronous API contract
  • Added proper HTTP error handling with response.EnsureSuccessStatusCode()

Key Changes:

// Before:
new System.Net.WebClient().DownloadFile(url, filename);

// After:
using (var response = httpClient.GetAsync(url).GetAwaiter().GetResult()) {
    response.EnsureSuccessStatusCode();
    using (var fileStream = File.Create(filename))
    using (var httpStream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult()) {
        httpStream.CopyTo(fileStream);
    }
}

The changes maintain full backward compatibility - the GetAsFile() method continues to be synchronous and all existing calling code works unchanged.

Fixes #10406.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • httpbin.org
    • Triggering command: /tmp/bin/Debug/net10.0/TestDownloadedCache (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Fix WebClient usage in Xamarin.ProjectTools Fix WebClient obsolete warning by replacing with HttpClient Aug 12, 2025
Copilot AI requested a review from jonathanpeppers August 12, 2025 21:46
@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 13, 2025 13:44
@jonathanpeppers jonathanpeppers enabled auto-merge (squash) August 13, 2025 13:46
@jonathanpeppers jonathanpeppers merged commit 8718016 into main Aug 13, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the copilot/fix-10406 branch August 13, 2025 14:42
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix WebClient usage in Xamarin.ProjectTools

3 participants