Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking change]: EnumConverter validates registered types to be enum #42696

Closed
2 of 3 tasks
LakshanF opened this issue Sep 24, 2024 · 0 comments · Fixed by #42847
Closed
2 of 3 tasks

[Breaking change]: EnumConverter validates registered types to be enum #42696

LakshanF opened this issue Sep 24, 2024 · 0 comments · Fixed by #42847
Assignees
Labels
binary incompatible Existing binaries may encounter a breaking change in behavior. breaking-change Indicates a .NET Core breaking change doc-idea Indicates issues that are suggestions for new topics [org][type][category] in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@LakshanF
Copy link
Member

LakshanF commented Sep 24, 2024

Description

EnumConverter is a type converter that converts to and from an enum type. EnumConverter now validates that the type to be registered is of an enum type.

Version

.NET 9 Preview 7

Previous behavior

The type to be registered was not validated to be an enum type.

New behavior

EnumConverter should be used only be used to convert to and from an enum type and will throw an ArgumentException if it is not. This also means that any derived classes of EnumConverter should also respect this requirement.

Type of breaking change

  • Binary incompatible: Existing binaries might 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 might require source changes to compile successfully.
  • Behavioral change: Existing binaries might behave differently at run time.

Reason for change

It seems logical to enforce the requirement that EnumConverter to be used to convert to and from enum types and likely an oversight not to do this earlier. However, the primary driving factor for this change was for trimming purposes. Trimming will not trim enum types but using EnumConverter for enum types required DynamicallyAccessedMembersAttribute annotation for an enum type. This meant using EnumConverter generates unnecessary trim warnings. There was a change this release to remove the annotation requirement. Part of this change was to enforce that EnumConverter should only be used with enums.

Recommended action

There is no easy workaround if an EnumConverter is used to convert to and from for a non-enum type.

Feature area

Extensions

Affected APIs

EnumConverter(Type) Constructor


Associated WorkItem - 317208

@LakshanF LakshanF added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Sep 24, 2024
@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Sep 24, 2024
@dotnetrepoman dotnetrepoman bot added ⌚ Not Triaged Not triaged binary incompatible Existing binaries may encounter a breaking change in behavior. and removed rerun-action-opened ⌚ Not Triaged Not triaged labels Sep 24, 2024
@sequestor sequestor bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Sep 25, 2024
@dotnetrepoman dotnetrepoman bot added ⌚ Not Triaged Not triaged and removed ⌚ Not Triaged Not triaged labels Sep 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr This issue will be closed (fixed) by an active pull request. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary incompatible Existing binaries may encounter a breaking change in behavior. breaking-change Indicates a .NET Core breaking change doc-idea Indicates issues that are suggestions for new topics [org][type][category] in-pr This issue will be closed (fixed) by an active pull request. Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants