DataGridView-related APIs now throw InvalidOperationException
Some APIs related to DataGridView now throw an InvalidOperationException if the object's DataGridViewCell.DataGridViewCellAccessibleObject.Owner value is null
.
Change description
In previous .NET versions, the affected APIs throw a NullReferenceException when they are invoked and the Owner property value is null
. Starting in .NET 6, these APIs throw an InvalidOperationException instead of a NullReferenceException if the Owner property value is null
when they're invoked.
Change category
This change affects binary compatibility.
Reason for change
Throwing an InvalidOperationException conforms to the behavior of the .NET runtime. It also improves the debugging experience by clearly communicating the invalid property.
Version introduced
.NET 6
Recommended action
Review your code and, if necessary, update it to prevent constructing the affected types with the Owner property as null
.
Affected APIs
The following table lists the affected properties and methods:
- System.Windows.Forms.DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.Bounds
- System.Windows.Forms.DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.DefaultAction
- System.Windows.Forms.DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.Name
- System.Windows.Forms.DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.Navigate(AccessibleNavigation)
- System.Windows.Forms.DataGridViewTopLeftHeaderCell.DataGridViewTopLeftHeaderCellAccessibleObject.State