Skip to content

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

Open
@AlgorithmicThoughts

Description

@AlgorithmicThoughts

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions