-
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
Support reading a byte array from a base64 string in JSON configuration #36034
Comments
Thanks for the proposal @thomaslevesque. The problem that I see with this is, how would we identify you have a base64 string to decode in the config file? Would we have to look at the property that we're binding and if it's type is |
Yes, at least that's what I had in mind. Actually, I probably shouldn't have mentioned JSON in the issue description, since it's not actually specific to JSON configuration. It should apply to any configuration source, since AFAIK the configuration binder doesn't care where the values come from, it just sees key/value pairs. |
Looks like if (type == typeof(byte[]))
{
if (value is null)
return null;
return Convert.FromBase64String(value);
} (with appropriate error handling, of course) I can submit a PR if this approach is acceptable. |
I don't have an objection to doing that. cc: @maryamariyan @davidfowl ? |
This seems reasonable. |
Is your feature request related to a problem? Please describe.
Currently, the configuration binder can't read a byte array from a base64 string.
For instance, if I have this:
and my appsettings.json file specifies the value for
Key
as a base64 string, it silently fails to bind my property, which remains null.Describe the solution you'd like
I'd like to be able to use base64 to specify byte array values in my configuration file. Instead, I have to declare the property as string, and parse it myself, which isn't very convenient.
(or write the values as a JSON array, which is even worse)
Describe alternatives you've considered
As mentioned above, declaring the property as a string and parsing it manually works, but isn't convenient.
Additional context
N/A
The text was updated successfully, but these errors were encountered: