I'm trying to write a section of code so that several applications
that all share some configuration options can load those options from
a single .config file. This code compiles and executes w/o error, but
it will not return the contents of any config file I give it.
The code to dump the sections always reports sections that do not
exist in the file.
Looking at appConfig.Type, the public key does not match the one in
the file.
What am i doing wrong?
FileInfo fi = new
FileInfo(Assembly.GetExecutingAssembly().Location) ;
ExeConfigurationFileMap fileMap = new
ExeConfigurationFileMap();
string configfile =
Path.Combine(fi.DirectoryName,@"global.config");
// string configfile = @"global.config";
fileMap.ExeConfigFilename = configfile; // relative path
names possible
// Open another config file
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(fi leMap,
ConfigurationUserLevel.None);
ConfigurationSection appConfig = config.AppSettings;
Console.WriteLine();
Console.WriteLine("Sections in "+config.FilePath);
// Loop to get the sections machine.config.
foreach (ConfigurationSection section in sections)
{
string name = section.SectionInformation.Name;
Console.WriteLine("Name: {0}", name);
Console.WriteLine(section.SectionInformation.GetRa wXml());
}
..config file===========
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Utilities.Global"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Utilities.Global>
<setting name="User" serializeAs="String">
<value>scott</value>
</setting>
<setting name="Password" serializeAs="String">
<value>tiger</value>
</setting>
<setting name="Source" serializeAs="String">
<value>oraHome</value>
</setting>
</Utilities.Global>
</applicationSettings>
</configuration>