Appsettings In Shared Config

Topics: Enterprise Library Core, General discussion
Dec 15, 2010 at 1:29 PM


I am using a single shared config across multiple applications in my solution. Each application has the following configuration in its app.config/web.config:

 <?xml version="1.0"?>
        <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <enterpriseLibrary.ConfigurationSource selectedSource="File-based Configuration Source">
            <add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                filePath="C:\Source\Configuration\Entlib.config" />

Now, if I put settings in the AppSettings element of the C:\Source\Configuration\Entlib.config file, they are not picked up by the application. Why is this?

Is there a way to achieve this behaviour (sharing configuration values across all applications)? I do not want to put them in the machine.config. I want all my configuration in the same file (C:\Source\Configuration\Entlib.config)



Dec 15, 2010 at 4:02 PM

You have to manually read thru it. Entlib configsource only read entlib related configuration. One approach I know is to have something like this;

            FileConfigurationSource config = new FileConfigurationSource(@"C:\temp\External.config");
            AppSettingsSection appSettings = config.GetSection("appSettings") as AppSettingsSection;

            string myKeyValue = appSettings.Settings["myKey"].Value;

Hope this helps.

Gino Terrado
Global Technologies and Solutions
Avanade, Inc.

Dec 15, 2010 at 6:52 PM

appSettings is a system configuration section, not an Entlib one, and therefore is ignorant of the existence of configuration sources. In fact, we have to jump through some hoops in the config tool to get them to show up in there at all, and they always have to be in the system configuration file for the appSettings API to find them.