You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on a .NET 4.8 application, I updated the packages Microsoft.Configuration.ConfigurationBuilders (Environment, Json, UserSecrets) from version 2.0 to 3.0. I have also updated my app.config file to reflect the latest version, shown here:
Before the update, when the version was 2.0. I was able to read the value from the secrets.xml file specified in the app.config key userSecretsFile:
var userKey = System.Configuration.ConfigurationManager.AppSettings["App:UserKey"];
After the update from version 2 to 3, this code no longer works and returns an empty string. I read the update guide but none of it provides troubleshooting guidance. I tried to update the path from ./App_Data/secrets.xml to ~/App_Data/secrets.xml for testing even then I get an empty string in the variable userKey.
Is there an additional step that needs to be performed in version 3 to make it work? Please suggest thanks
The text was updated successfully, but these errors were encountered:
I assume from the 'App_Data' part of your path that this is in an ASP.Net application. In which case, ~/App_Data/secrets.xml should be the correct way to go in your case. And I believe that should also be the case for non-ASP.Net apps as well in 3.0.
I do find it curious that your config file has a raw default value for the secret and then when you read the appSetting in your code you get an empty string. That suggests to me that something else is going on here - because if the builder failed to find your secret file, it should just leave the default Hello World alone. Did you by chance figure this out on your own?
Incidentally, the 'User Secrets' part of this config builder name kind of implies that it is bringing secrets into the application. I would recommend against puting secrets in a file within the application itself like you're doing here. Secrets should always live somewhere outside the application and only be brought in when appropriate. (Maybe you're just testing or maybe the data you've got in your secrets.xml isn't actually secret. But it would be irresponsible of me to not say anything. 😉)
Thank you for the response @StephenMolloy
How I was able to resolve this was in Visual Studio I right-clicked the file and updated the property Copy to Output Directory from Do not copy to Copy if newer and it worked but I didn't have to do this in the previous version? Is this an undocumented step that needs to happen for version 3?
I am working on a .NET 4.8 application, I updated the packages
Microsoft.Configuration.ConfigurationBuilders
(Environment, Json, UserSecrets) from version 2.0 to 3.0. I have also updated my app.config file to reflect the latest version, shown here:The structure of the secrets.xml file is given below:
Before the update, when the version was 2.0. I was able to read the value from the secrets.xml file specified in the app.config key userSecretsFile:
var userKey = System.Configuration.ConfigurationManager.AppSettings["App:UserKey"];
After the update from version 2 to 3, this code no longer works and returns an empty string. I read the update guide but none of it provides troubleshooting guidance. I tried to update the path from
./App_Data/secrets.xml
to~/App_Data/secrets.xml
for testing even then I get an empty string in the variable userKey.Is there an additional step that needs to be performed in version 3 to make it work? Please suggest thanks
The text was updated successfully, but these errors were encountered: