-
Notifications
You must be signed in to change notification settings - Fork 6.1k
EnumConverter breaking change #42847
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --- | ||
| title: "Breaking change: EnumConverter validates registered types to be enum" | ||
| description: Learn about the .NET 9 breaking change in networking where EnumConverter now validates that the type to be registered is an enum type. | ||
| ms.date: 10/04/2024 | ||
| --- | ||
| # EnumConverter validates registered types to be enum | ||
|
|
||
| <xref:System.ComponentModel.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. | ||
|
|
||
| ## Previous behavior | ||
|
|
||
| Previously, the type to be registered was not validated to be an `enum` type. | ||
|
|
||
| ## New behavior | ||
|
|
||
| Starting in .NET 9, <xref:System.ComponentModel.EnumConverter> throws an <xref:System.ArgumentException> if the type to be converted is not an `enum` type. Any derived classes of <xref:System.ComponentModel.EnumConverter> should also respect this requirement. | ||
|
|
||
| ## Version introduced | ||
|
|
||
| .NET 9 Preview 7 | ||
|
|
||
| ## Type of breaking change | ||
|
|
||
| This change can affect [binary compatibility](../../categories.md#binary-compatibility) and is also a [behavioral change](../../categories.md#behavioral-change). | ||
|
|
||
| ## Reason for change | ||
|
|
||
| It is logical to enforce the requirement that <xref:System.ComponentModel.EnumConverter> be used to convert to and from `enum` types only. It was likely an oversight that this requirement wasn't added earlier. | ||
|
|
||
| However, the primary driving factor for this change was for trimming purposes. [Trimming](../../../deploying/trimming/prepare-libraries-for-trimming.md) doesn't trim `enum` types, but using <xref:System.ComponentModel.EnumConverter> for `enum` types required <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute> annotation for an `enum` type. This means that using `EnumConverter` generates unnecessary trim warnings. A recent change removed the annotation requirement. Part of the reason for that change was to enforce that `EnumConverter` only be used with `enums`. | ||
|
|
||
| ## Recommended action | ||
|
|
||
| There is no easy workaround if an <xref:System.ComponentModel.EnumConverter> is used to convert to and from a non-`enum` type. | ||
|
|
||
| ## Affected APIs | ||
|
|
||
| - <xref:System.ComponentModel.EnumConverter.%23ctor(System.Type)> constructor | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.