runtime: ConfigurationBuilder - Configuration.Json: Binding a Dictionary error when Key contains an string url like http://www.google.es
Describe the bug
Im reading a json file to a dictionary<string,string> like:
{
"auths": {
"https://www.google.es": {
"uri": "https://www.google.es"
}
}
}
having the POCO class
public class MyClass
{
[ConfigurationProperty("auths", IsRequired = false)]
public Dictionary<string, OtherObject> Auths { get; set; }
}
When i load it using ConfigurationRoot like
public MyClass Read()
{
IConfigurationRoot configuration =
new ConfigurationBuilder()
.AddJsonFile("path_to_json_file", optional: true, reloadOnChange: true)
.Build();
// Try Parse and return (if will exception in case of binding error)
var _settings= new MyClass();
configuration.Bind(_settings);
return _settings;
}
The issue is that the Dictionary item contains https only on the Key property. Looks like it’s ignoring or having issues with https://…
Not sure if it’s an intended feature or a bug.
To Reproduce
Steps to reproduce the behavior:
- Using version ‘3.1.8’ of package ‘Microsoft.Extensions.Configuration.Json’
- Run this code ‘with files in description’
- See error in the screenshot attached
Expected behavior
Dictionary Key Item should contains https://www.google.es
Screenshots
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (10 by maintainers)
Looks like this issue has been encountered previously, e.g. https://github.com/aspnet/Configuration/issues/792 https://github.com/dotnet/extensions/issues/782. Sounds like something we should address instead of our usual answer that
:
is a reserved character and this issue is by design.Maybe we want to have an escape sequence for json config so this is allowed? Or a flag to disable the ‘:’ behavior just for Json?
If any change is made, we should port it to the Newtonsoft.Json config provider in Extensions.