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 |
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.