BindingSource.SortDescriptions doesn't return null

BindingSource.SortDescriptions has been updated to return an empty ListSortDescriptionCollection instead of null if the data source is not an IBindingListView.

Version introduced

.NET 9 Preview 1

Previous behavior

Previously, BindingSource.SortDescriptions returned null if the data source wasn't an IBindingListView.

New behavior

Starting in .NET 9, BindingSource.SortDescriptions returns an empty ListSortDescriptionCollection if the data source is not an IBindingListView.

Change category

This change is a behavioral change.

Reason for change

The previous behavior was incorrect.

BindingSource.SortDescriptions has historically returned null if the data source was not an IBindingListView. However BindingSource.SortDescriptions implements IBindingListView.SortDescriptions, whose return type is non-nullable. To align with the interface it implements, BindingSource.SortDescriptions was changed to return an empty ListSortDescriptionCollection instead.

If your code expects null from BindingSource.SortDescriptions for any reason, update your code to expect an empty ListSortDescriptionCollection instead.

Affected APIs