IIS - Error: Unrecognized Attribute "configBuilders"

2.2k Views Asked by At

Error Message

I've been trying to get an ASP.NET API setup, but I keep getting this error on the IIS Server when trying to check the Connection Strings. The project is a straight up new ASP.NET API Project with only 2 added variables to the registration table.

My Connection String (web.config):

<configBuilders>
<builders>
<add name="Secrets" userSecretsId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxx" />
</builders>
</configBuilders>

<connectionStrings configBuilders="Secrets">
<add name="DefaultConnection" connectionString="Data Source=SERVER;Initial Catalog=myAPIApp;Persist Security Info=True;User ID=xxxxxxx;Password=xxxxxxx" />
</connectionStrings>
1

There are 1 best solutions below

2
On

After installed the below Nuget package,
https://www.nuget.org/packages/Microsoft.Configuration.ConfigurationBuilders.Environment/
We should register configbuilder firstly before using a custom configuration builder.

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection,
             System.Configuration, Version=4.0.0.0, Culture=neutral,
             PublicKeyToken=b03f5f7f11d50a3a"
             restartOnExternalChanges="false" requirePermission="false" />
  </configSections>

Please refer to my configuration of obtaining the ServiceID from System Environment Variables preferentially.

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection,
             System.Configuration, Version=4.0.0.0, Culture=neutral,
             PublicKeyToken=b03f5f7f11d50a3a"
             restartOnExternalChanges="false" requirePermission="false" />
  </configSections>

  <configBuilders>
    <builders>
      <add name="Secrets" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </builders>
  </configBuilders>

  <appSettings configBuilders="Secrets">
    <add key="ServiceID" value="ServiceID value from web.config" />
    <add key="ServiceKey" value="Spotify" />
  </appSettings>

  <connectionStrings configBuilders="Secrets">
    <add name="default" connectionString="Data Source=web.config/mydb.db" />
  </connectionStrings>

ServiceID/ServiceKey will be obtained the value from System Environment Variables if it sets.
Feel free to let me know if the problem still exists.