[Breaking change]: WinForms will raise HttpClient exceptions instead of WebClient in .NET 9 #41485
Closed
1 of 3 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 9
Work items for the .NET 9 release
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
in-pr
This issue will be closed (fixed) by an active pull request.
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
source incompatible
Source code may encounter a breaking change in behavior when targeting the new version.
Description
Instead of
WebException
from WebClient, it will raiseHttpRequestException
,TaskCanceledException
etc. when network errors occur from PictureBox loading image from URL.PR dotnet/winforms#11542
@lonitra
Version
.NET 9 Preview 6
Previous behavior
When PictureBox failed to load image from URL due to networking error, WebException is thrown: https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.openread#system-net-webclient-openread(system-string)
New behavior
When PictureBox failed to load image from URL due to networking error,
HttpException
orTaskCanceledException
are thrown: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.getstreamasync#system-net-http-httpclient-getstreamasync(system-uri-system-threading-cancellationtoken)Type of breaking change
Reason for change
WebClient is being obsolete in .NET 9 runtime.
Recommended action
Following conditions are met:
System.Windows.Forms.PictureBox.UseWebRequest
appcontext switch istrue
.WebException
, not its parentInvalidOperationException
(which HttpClient also throws) or "catch all" block (catch { }
,catch (Exception) { }
).Feature area
Windows Forms
Affected APIs
PictureBox control.
Associated WorkItem - 281895
The text was updated successfully, but these errors were encountered: