Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
When Microsoft.Extensions.Configuration.Xml is used to read an XML document that has repeated XML elements without a Name
attribute, the Configuration
entries created with these repeated elements now have an index appended to their configuration path.
.NET 6
Consider the following XML snippets that show repeated elements without a distinguishing Name
attribute.
<settings>
<Data ConnectionString="TestConnectionString" />
<Data Provider="MySql" />
</settings>
<configuration>
<Level1>
<Level2 Key1="Value1" />
<Level2 Key2="Value2" />
</Level1>
</configuration>
The configurations created from these XML files were:
Data:ConnectionString = TestConnectionString
Data:Provider = MySql
and
Level1:Level2:Key1 = Value1
Level1:Level2:Key2 = Value2
respectively.
The configurations created from the XML files in the Previous behavior section are now:
Data:0:ConnectionString = TestConnectionString
Data:1:Provider = MySql
and
Level1:Level2:0:Key1 = Value1
Level1:Level2:1:Key2 = Value2
respectively.
This change can affect binary compatibility.
This change was introduced to fully support repeated XML elements that don't have a Name
attribute. The previous behavior only allowed for repeated elements to set unique values (using attributes or subelements). If repeated XML elements had the same attribute, an exception was thrown.
To get the original behavior, you can update your XML to collapse the two attributes into the same element. For example:
<configuration>
<Level1>
<Level2 Key1="Value1" Key2="Value2" />
</Level1>
</configuration>
Alternatively, you can update your code to expect indices (such as 0, 1, 2) in the IConfiguration
keys:
configRoot.GetSection("Level1:Level2")
becomes
configRoot.GetSection("Level1:Level2:0")
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining