Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Some Windows Forms properties now throw an ArgumentOutOfRangeException for invalid arguments, where previously they did not.
Change description
Previously, these properties threw various exceptions, such as NullReferenceException, IndexOutOfRangeException, or ArgumentException, when passed out-of-range arguments. Starting in .NET 5, these properties now throw an ArgumentOutOfRangeException when passed arguments that are out of range.
Throwing an ArgumentOutOfRangeException 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 ArgumentOutOfRangeException when setting the property.
Affected APIs
The following table lists the affected properties and parameters:
Property | Parameter name | Version added |
---|---|---|
ListBox.IntegerCollection.Item[Int32] | index |
5.0 Preview 5 |
TreeNode.ImageIndex | value |
5.0 Preview 6 |
TreeNode.SelectedImageIndex | value |
5.0 Preview 6 |