[Breaking change]: Stop skipping configuration binding a dictionary with a key that has empty value #36431
Closed
1 of 3 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
doc-idea
Indicates issues that are suggestions for new topics [org][type][category]
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
In previous versions, when binding configuration to a dictionary type, any keys listed in the configuration without corresponding values would be skipped, resulting in their non-creation within the dictionary. However, a recent breaking change alters this behavior, whereby such keys will no longer be skipped but instead will be automatically created with their default values. This change ensures that all keys listed in the configuration will be present within the dictionary, streamlining the process and avoiding potential issues with missing keys. Developers should be aware of this update and adjust their code accordingly to accommodate the new behavior.
Version
.NET 8 Preview 5
Previous behavior
Consider the following example:
Configuration
Code
Output
Please take note that the third key, q3, is currently being skipped, resulting in no corresponding dictionary entry being created for it.
New behavior
With the new behavior, the resulting output will now include the q3 key, which was previously skipped. This key will be created and initialized with the default value within the generated dictionary. This change ensures that all listed keys are accounted for, eliminating any potential omissions, and promoting consistency in the dictionary structure.
Type of breaking change
Reason for change
This change ensures that all keys listed in the configuration will be present within the dictionary, streamlining the process and avoiding potential issues with missing keys. Developers should be aware of this update and adjust their code accordingly to accommodate the new behavior. The users request this new behavior. dotnet/runtime#66229
Recommended action
Users should be aware of the new behavior, which involves the automatic population of dictionary entries with empty values listed in the configuration during the binding process. This change necessitates that users verify and adapt their application logic to accommodate the presence of these newly created entries. If the new behavior is undesirable, the workaround involves removing the empty value entries from the configuration. By eliminating these entries, users can revert to the previous behavior and avoid automatic population of dictionary entries with empty values during the binding process. This allows users to maintain the desired configuration structure according to their specific needs and preferences.
Feature area
Extensions
Affected APIs
ConfigurationBinder
IConfigurationRoot extension methods
OptionsConfigurationServiceCollectionExtensions
Associated WorkItem - 143185
The text was updated successfully, but these errors were encountered: