WinForms methods now throw ArgumentException
Some Windows Forms methods now throw an ArgumentException for invalid arguments, where previously they did not.
Change description
Previously, passing arguments of an unexpected or incorrect type to certain Windows Forms methods would result in an indeterminate state. Starting in .NET 5, these methods now throw an ArgumentException when passed invalid arguments.
Throwing an ArgumentException conforms to the behavior of the .NET runtime. It also improves the debugging experience by clearly communicating which argument is invalid.
Version introduced
.NET 5.0
Recommended action
- Update the code to prevent passing invalid arguments.
- If necessary, handle an ArgumentException when calling the method.
Affected APIs
The following table lists the affected methods and parameters:
Method | Parameter name | Condition | Version added |
---|---|---|---|
System.Windows.Forms.TabControl.GetToolTipText(Object) | item |
Argument is not of type TabPage. | Preview 1 |
System.Windows.Forms.DataFormats.GetFormat(String) | format |
Argument is null , String.Empty, or white space. |
Preview 5 |
InputLanguageChangedEventArgs(CultureInfo, Byte) | culture |
Unable to retrieve an InputLanguage for the specified culture. |
Preview 7 |
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for