Closed ondrejtucny closed 1 month ago
Tagging subscribers to this area: @dotnet/area-extensions-configuration See info in area-owners.md if you want to be subscribed.
Author: | ondrejtucny |
---|---|
Assignees: | - |
Labels: | `area-Extensions-Configuration` |
Milestone: | - |
Doesn't appear to be a regression. This is happening because the target property already has a value of
"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""
And configuration will append to this. So it ends up passing down.
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "--"
Probably we'd need API to control this if we wanted different behavior. I think this is the same issue as https://github.com/dotnet/runtime/issues/36569
Closing as this is by design.
Description
The property
DateTimeFormatInfo.AbbreviatedMonthNames
requires astring[]
with exactly 13 items. When deserializing aDateTimeFormatInfo
from a configuration JSON object usingIConfiguration.Get<T>()
, the setter of the property causes an exception claiming that the length of the input array is not 13. However, in the input JSON, the array does have exactly 13 items.When deserialized using
JsonSerializer
, it works correctly.Reproduction Steps
This program demonstrates the problem:
Expected behavior
Be able to deserialize
DateTimeFormatInfo
instances from configuration, including theAbbreviatedMonthNames
and other similar properties.Actual behavior
The program used to reproduce the issue causes the following exception:
Regression?
Reproduced on .NET 5, 6, 7, 8 Preview 3 using DotNetFiddle.
Known Workarounds
When a custom class with a
string[] AbbreviatedMonthNames
property is used, the issue does not appear. In fact, the setter gets the expected 13-item array. This can be validated in the example code above.Configuration
Originally spotted the issue on .NET SDK 6.0.313, running on Windows Server 2019.
Other information
No response