views:

638

answers:

2

I have a custom .NET addin for an application and I am trying to create configSections for the addin's config file. The trouble is I am not able to read that section If load the configuration using the OpenMapperExeConfiguration/OpenExeConfiguration.

Here is my config file(MyTest.dll.config)

<configuration>
  <configSections>
    <section name="test" type="MyTest, Test.ConfigRead"/>
    </configSections>
    <test>
      ..Stuff here
     </test>
    <appSettings>
     <add key="uri" value="www.cnn.com"/>
    </appSettings>
</configuration>

Here is my code sample to access the test configSection

ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();  
fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + "config";    
Configuration applicationConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);
//Using OpenExeConfiguration doesnt help either.
//Configuration applicationConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
//Accessing test section
applicationConfig.GetSection("test");

//Accessing AppSettings works fine.
AppSettingsSection appSettings = (AppSettingsSection)applicationConfig.GetSection("appSettings");
appSettings.Settings["uri"].Value;

As shown appsettings value can be read just fine. Is it possible to have configSections in any other config other than the main application's config file?

A: 

Configuration settings apply at application (app.config located in the application's root for .EXE, Web root for Web applications) and machine(machine.config located in [System Root]\Microsoft.NET\Framework[CLR Version]\CONFIG) level.

The only other config file used is the policy config file which is used to create assembly versioning policies and is linked to the assembly by making of use of the AL tool. This is obviously what you do not want to do.

Try to merge the add in's config sections into the current application's config section to create one app level config file or else put them in machine.config file.

Lonzo
A: 

Are you missing a '.' delimiter?

fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + "config"; 
add the '.':
fileMap.ExeConfigFilename = Assembly.GetExecutingAssembly().Location + ".config";
csharptest.net