I cannot figure out why i am getting this error. I am trying to get a value from appSettings section of a mapped config file.
Here is my config file:
<?xml version="1.0" encoding="utf-8"?><configuration><configSections><section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /></configSections><appSettings> <!-- Need to configure.--><add key="ServiceDisplayName" value="Scheduler-aaaa" /><add key="ServiceName" value="SchedulerService-aaaa" /><add key="SchedulerTime" value="05:00 AM" /><!-- 12 hour format--><add key="RoutingInterval" value="5"/><add key="ADSyncInterval" value="2"/><add key="ReportPath" value="C:\inetpub\wwwroot\aaaa\Reports\DefaultReports"/><add key="ReportPathCustom" value="C:\inetpub\wwwroot\aaaa\Reports\CustomReports"/><add key="ApplicationUrl" value="https://mms.com/aaaa/"/><add key="ServiceUrl" value="https://temp.com/aaaa/Inspection/Service"/><add key="ClientSettingsProvider.ServiceUri" value="" /><add key="EmailAddress" value="support@mms.com" /></appSettings><connectionStrings><add name="CustomerDB" connectionString="Provider=SQLOLEDB.1;Data Source=.\temp;User ID=mm;PWD=mm;Initial Catalog=35testupdate" /></connectionStrings><cachingConfiguration /><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup><system.web><membership defaultProvider="ClientAuthenticationMembershipProvider"><providers><add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" /></providers></membership><roleManager defaultProvider="ClientRoleProvider" enabled="true"><providers><add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" /></providers></roleManager></system.web></configuration>
Here is my code:
ExeConfigurationFileMap fm = new ExeConfigurationFileMap(path); fm.ExeConfigFilename = path;//"Scheduler.exe.config"; Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(fm, ConfigurationUserLevel.None); if (conf.AppSettings.Settings["SchedulerTime"] != null) //<<ERROR { return conf.AppSettings.Settings["SchedulerTime"].Value; }
I have tried just getting the section of appSettings, but it is null when i do this:
conf.GetSection("appSettings");
Any help would be appreciated.