[Breaking change]: EnumConverter validates registered types to be enum #42696
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.
Description
EnumConverter
is a type converter that converts to and from anenum
type.EnumConverter
now validates that the type to be registered is of anenum
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 anenum
type and will throw anArgumentException
if it is not. This also means that any derived classes of EnumConverter should also respect this requirement.Type of breaking change
Reason for change
It seems logical to enforce the requirement that
EnumConverter
to be used to convert to and fromenum
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 anenum
type. This meant usingEnumConverter
generates unnecessary trim warnings. There was a change this release to remove the annotation requirement. Part of this change was to enforce thatEnumConverter
should only be used withenums
.Recommended action
There is no easy workaround if an
EnumConverter
is used to convert to and from for anon-enum
type.Feature area
Extensions
Affected APIs
EnumConverter(Type) Constructor
Associated WorkItem - 317208
The text was updated successfully, but these errors were encountered: