Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple AppSettings files, is it possible?

I want to create 3 AppSettings config files:

  • Database.config
  • Messages.config
  • Global.config

And after add in my App.config:

<appSettings file="Database.config" /> <appSettings file="Messages.config" /> <appSettings file="Global.config" /> 

But when I try to access a key that there is in one of three files with the ConfigurationManager, I got the following error:

Configuration system failed to initialize. Sections must only appear once per config file.

I cannot have more than one AppSettings config file?

like image 344
Vinicius Ottoni Avatar asked Jul 05 '12 19:07

Vinicius Ottoni


People also ask

Can we have multiple app config files?

You cannot use multiple configuration files (i.e. one per library project) without coding.

Are AppSettings cached?

AppSettings is cached. You can improve performance by further caching to limit namevaluecollection lookups.


1 Answers

You can't have more than one appsettings because that's the name of a section. You can add a new section though that uses the same kind of section definition as appsettings. E.g.,

<configuration>     <configSections>         <section name="DatabaseConfig" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>     </configSections>     ....     <DatabaseConfig>        <add key="Whatever" value="stuff"/>     </DatabaseConfig> </configuration> 
like image 131
aquinas Avatar answered Sep 20 '22 05:09

aquinas