PictureBox raises HttpClient exceptions

When PictureBox loads an image from a URL and a network error occurs, it now raises HttpClient exceptions, such as HttpRequestException and TaskCanceledException, instead of WebException.

Version introduced

.NET 9 Preview 6

Previous behavior

Previously, when PictureBox failed to load an image from a URL due to a network error, a WebException was thrown.

New behavior

Starting in .NET 9, when PictureBox fails to load an image from a URL due to a network error, HttpRequestException or TaskCanceledException is thrown.

Change category

This change is a behavioral change.

Reason for change

WebClient is obsolete.

Update your code to catch HttpRequestException and TaskCanceledException instead of WebException.

Affected APIs