TableLayoutStyleCollection throws ArgumentException

TableLayoutStyleCollection enforces the type passed to its collection operations. The affected APIs now throw an ArgumentException instead of an InvalidCastException if the input is not of type TableLayoutStyle.

Version introduced

.NET 8 Preview 1

Previous behavior

Previously, if the input couldn't be converted to type TableLayoutStyle, an InvalidCastException was thrown.

New behavior

Starting in .NET 8, if the input can't be converted to type TableLayoutStyle, an ArgumentException is thrown.

Change category

This change is a behavioral change.

Reason for change

This change helps to make exception types consistent across the code base.

For most scenarios, this change should not have a significant impact. However, if you previously handled InvalidCastException, update your code to handle ArgumentException instead.

Affected APIs