-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Configuration Binding a dictionary with a key that has empty value skips the key as well #66229
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsI am using Configuration Binding to read a config file. Empty dictionary value leads to not generating an entry for key as well. Here is where I bind the configuration to a type defined in my project DistributedQueueConfig
Attached the json file used. This is examining opts after Bind. opts.Namespaces[0].Queues.Count q4 which has empty value does have an entry in the dictionary which is not expected. When I used JsonSerializer.Deserialize(), I can see q4 in the object. It is valid for a queue to not have any queueproperties fields set, but still should show up in the list of queues. I tried both BinderOptions which has no effect. This seems to be a bug.
queue_config.json
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsI am using Configuration Binding to read a config file. Empty dictionary value leads to not generating an entry for key as well. Here is where I bind the configuration to a type defined in my project DistributedQueueConfig var opts = new DistributedQueueConfig();
var config = hostContext.Configuration.GetSection("queueConfig");
// bind manually
config.Bind(opts); Attached the json file used. This is examining opts after Bind.
q4 which has empty value does have an entry in the dictionary which is not expected. When I used JsonSerializer.Deserialize(), I can see q4 in the object. It is valid for a queue to not have any queueproperties fields set, but still should show up in the list of queues. I tried both BinderOptions which has no effect. This seems to be a bug. /// <summary>
/// Top level of the config json
/// </summary>
public class DistributedQueueConfig
{
/// <summary>
/// Contains list of namespaces.
/// </summary>
[JsonPropertyName("namespaces")]
public IList<QueueNamespaces> Namespaces { get; set; }
}
public class QueueNamespaces
{
/// <summary>
/// Namespace value
/// </summary>
[JsonPropertyName("namespace")]
public string Namespace { get; set; }
/// <summary>
/// Map of queue name and its properties.
/// </summary>
[JsonPropertyName("queues")]
public Dictionary<string, QueueProperties> Queues { get; set; } = new ();
}
public class QueueProperties
{
/// <summary>
/// The date when the queue is marked to be dequeueOnly.
/// Used to determine if queue is AvailableForEnqueueing.
/// </summary>
[JsonPropertyName("creationDate")]
public DateTimeOffset? CreationDate { get; set; }
/// <summary>
/// The date when the queue is marked to be dequeueOnly.
/// Used to determine if queue is AvailableForEnqueueing.
/// </summary>
[JsonPropertyName("dequeueOnlyMarkedDate")]
public DateTimeOffset? DequeueOnlyMarkedDate { get; set; } = default(DateTimeOffset);
} queue_config.json {
"queueConfig": {
"namespaces": [
{
"namespace": "devnortheurope",
"queues": {
"q1": {
"dequeueOnlyMarkedDate": "2022-01-20T12:49:03.395150-08:00"
},
"q2": {
"dequeueOnlyMarkedDate": "2022-01-20T12:49:03.395150-08:00"
}
}
},
{
"namespace": "devnortheurope2",
"queues": {
"q3": {
"dequeueOnlyMarkedDate": "2022-01-20T12:49:03.395150-08:00"
},
"q4": {
}
}
}
]
}
}
|
Should be fixed by #86485 |
Filed the breaking change doc dotnet/docs#36431 |
I am using Configuration Binding to read a config file. Empty dictionary value leads to not generating an entry for key as well.
Here is where I bind the configuration to a type defined in my project DistributedQueueConfig
Attached the json file used.
This is examining opts after Bind.
q4 which has empty value does have an entry in the dictionary which is not expected. When I used JsonSerializer.Deserialize(), I can see q4 in the object. It is valid for a queue to not have any queueproperties fields set, but still should show up in the list of queues. I tried both BinderOptions which has no effect. This seems to be a bug.
queue_config.json
The text was updated successfully, but these errors were encountered: