Skip to content

[Breaking change]: TableLayoutStyleCollection will throw ArgumentException instead of InvalidCastException #33694

Closed

Description

@dreddy-work

Description

The TableLayoutStyleCollection in Winforms enforces the type passed to its collection operations and throws an exception if the type is not of TableLayoutStyle. Previously, the public APIs would throw an InvalidCastException, but they will now throw an ArgumentException. The current behavior regarding InvalidCastException is not explicitly stated in the existing documentation. The following operations could potentially throw an ArgumentException:

Add()
Remove()
Index - setter ( i.e. this[..] = ..)

Version

.NET 8 Preview 1

Previous behavior

If the input cannot be converted to the type TableLayoutStyle, an InvalidCastException will be thrown during the operation.

New behavior

If the input cannot be converted to the type TableLayoutStyle, an ArgumentException will be thrown during the operation.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

Existing documentation clearly notes that type should be of type TableLayoutStyle. Making exceptions consistent across codebase.

Recommended action

This change should not have a significant impact on most scenarios. However, if users were previously handling the InvalidCastException exception, which is not documented, they will now need to make changes to handle the ArgumentException, which is documented instead.

Feature area

Windows Forms

Affected APIs

in TableLayoutStyleCollection

Add()
Remove()
Index - setter ( i.e. this[..] = ..)


Associated WorkItem - 62399

Activity

  1. added
    breaking-change
    binary incompatible
    on Jan 24, 2023
  2. added
    🏁 Release: .NET 8
    and removed
    ⌚ Not Triaged
    on Jan 24, 2023
  3. added
    🗺️ reQUEST
    on Feb 3, 2023
  4. added
    📌 seQUESTered
    and removed
    🗺️ reQUEST
    on Feb 3, 2023
  5. ghost added
    in-pr
    on Feb 6, 2023
  6. moved this from 🔖 Ready to 🏗 In progress in dotnet/docs February 2023 sprinton Feb 6, 2023
  7. moved this from 🏗 In progress to ✅ Done in dotnet/docs February 2023 sprinton Feb 14, 2023
  8. ghost removed
    in-pr
    on Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 8📌 seQUESTeredbinary incompatiblebreaking-change

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions