DataGridView-related APIs 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 5, these APIs throw an InvalidOperationException instead of a NullReferenceException if the Owner property value is null when they're invoked.

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 5.0

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 APIs:

See also