Skip to content
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

.NET v4.8: updating the Microsoft.Configuration.ConfigurationBuilders to version 3.0 does not work #272

Open
AlgorithmicThoughts opened this issue Feb 12, 2025 · 0 comments

Comments

@AlgorithmicThoughts
Copy link

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:

<configBuilders>
    <builders>
      <add name="Environment" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="Secrets" 
           userSecretsFile="./App_Data/secrets.xml" 
           mode="Greedy" 
           type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>      
    </builders>
  </configBuilders>

The structure of the secrets.xml file is given below:

<root>
<secrets ver="1.0">
    <secret name="App:UserKey" value="Hello World"/>
</secrets>
</root>

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant