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]: Repeated XML Elements Now Have Index Key in Microsoft.Extensions.Configuration.Xml #30660

Closed
1 of 2 tasks
eerhardt opened this issue Aug 12, 2022 · 0 comments · Fixed by #31597
Closed
1 of 2 tasks
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] Pri1 High priority, do before Pri2 and Pri3

Comments

@eerhardt
Copy link
Member

Description

When Microsoft.Extensions.Configuration.Xml is used to read an XML document that has repeated XML elements without a Name attribute, for example:

<settings>
  <Data ConnectionString="TestConnectionString" />
  <Data Provider="MySql" />
</settings>

-or-

<configuration>
    <Level1>
        <Level2 Key1="Value1" />
        <Level2 Key2="Value2" />
    </Level1>
</configuration>

The Configuration entries created with these repeated elements will now have an index appended to their configuration path.

Version

6.0.0

Version

Other (please put exact version in description textbox)

Previous behavior

The Configurations created from the above XML files were:

Data:ConnectionString = TestConnectionString
Data:Provider = MySql

and

Level1:Level2:Key1 = Value1
Level1:Level2:Key2 = Value2

respectively.

New behavior

The Configurations created from the above XML files are now:

Data:0:ConnectionString = TestConnectionString
Data:1:Provider = MySql

and

Level1:Level2:0:Key1 = Value1
Level1:Level2:1:Key2 = Value2

respectively.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.

Reason for change

This change was introduced to fully support repeated XML elements without a Name attribute. The previous behavior only allowed for repeated elements to set unique values (attributes or sub-elements). If repeated XML elements had the same attribute, an exception would be thrown.

Recommended action

  1. You can update your XML to collapse the 2 attributes into the same element, and get the original behavior. For example,
<configuration>
    <Level1>
        <Level2 Key1="Value1" Key2="Value2" />
    </Level1>
</configuration>
  1. You can update your code to expect 0, 1, 2, etc. indices in the IConfiguration keys.
configRoot.GetSection("Level1:Level2")

becomes

configRoot.GetSection("Level1:Level2:0")

Feature area

Extensions

Affected APIs

https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.xmlconfigurationextensions
https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.xml.xmlstreamconfigurationprovider
https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.xml.xmlconfigurationsource

@eerhardt eerhardt 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 Aug 12, 2022
@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged binary incompatible Existing binaries may encounter a breaking change in behavior. labels Aug 12, 2022
@gewarren gewarren removed the ⌚ Not Triaged Not triaged label Aug 15, 2022
@gewarren gewarren moved this to 🔖 Ready in dotnet/docs October Sprint Sep 30, 2022
@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label Oct 4, 2022
Repository owner moved this from 🔖 Ready to ✅ Done in dotnet/docs October Sprint Oct 4, 2022
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Oct 4, 2022
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] Pri1 High priority, do before Pri2 and Pri3
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants