title: App.config not accessible when built in Settings
body: <p>I have a very simple app that I am trying to build an app.config using the Settings property. The app.config is built, but when run, the keys are not retrieving values.</p>
  
  <p>I had originally used the adding of an Application Configuration File from the project and hand building the app.config with great success The hand-built app.config is below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;appSettings&gt;
      &lt;add key="Hosppath" value="C:\events\inbound"/&gt;
      &lt;add key="Vendpath" value="C:\events\outbound"/&gt;
      &lt;add key="Hospname" value="OBLEN_COB_Active_Inv_Advi_Daily_.csv"/&gt;
      &lt;add key="Vendname" value="Advi_OBlen_Active_Inv_Ack_Daily_.csv"/&gt;
      &lt;add key="Hospkey" value="invoice_number"/&gt;
      &lt;add key="Vendkey" value="invoice"/&gt;
      &lt;add key="Outpath" value="C:\events\Reports"/&gt;
      &lt;add key="Outname" value="OB_Exception_Report_.xlsx"/&gt;
      &lt;add key="Hospexcpt" value="O'Bleness Exceptions"/&gt;
      &lt;add key="Vendexcpt" value="AdviCare Exceptions"/&gt;
    &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The calling class is here:</p>
  
  <pre><code>using System;
  using System.Configuration;
  
  namespace LoadSettings
  {
      public static class ConfigReader
      {
          public static bool ReadAllSettings()
          {
              var success = false;
              var appSettings = ConfigurationManager.AppSettings;
  
              if(appSettings.Count &gt; 0)
              {
                  success = true;
              }
              return success;
          }
  
          public static string ReadSetting(string key)
          {
              string result = "";
  
              var appSettings = ConfigurationManager.AppSettings;
              result = appSettings[key] ?? "Not Found";
  
              return result;
          }
      }
  }
  </code></pre>
  
  <p>The Main() function looks like this:</p>
  
  <pre><code>using System;
  using System.Configuration;
  
  namespace LoadSettings
  {
      class Program
      {
          static void Main(string[] args)
          {
              string hospPath;
              string vendPath;
              string hospName;
              string vendName;
              string hospKey;
              string vendKey;
              string rptPath;
              string rptName;
              string sht1Name;
              string sht2Name;
  
              if (ConfigReader.ReadAllSettings())
              {
                  hospPath = ConfigReader.ReadSetting("Hosppath");
                  vendPath = ConfigReader.ReadSetting("Vendpath");
                  hospName = ConfigReader.ReadSetting("Hospname");
                  vendName = ConfigReader.ReadSetting("Vendname");
                  hospKey = ConfigReader.ReadSetting("Hospkey");
                  vendKey = ConfigReader.ReadSetting("Vendkey");
                  rptPath = ConfigReader.ReadSetting("Outpath");
                  rptName = ConfigReader.ReadSetting("Outname");
                  sht1Name = ConfigReader.ReadSetting("Hospexcpt");
                  sht2Name = ConfigReader.ReadSetting("Vendexcpt");
  
                  Console.WriteLine("The hospital file path is:      {0}", hospPath);
                  Console.WriteLine("The vendor file path is:        {0}", vendPath);
                  Console.WriteLine("The hospital file name is:      {0}", hospName);
                  Console.WriteLine("The vendor file name is:        {0}", vendName);
                  Console.WriteLine("The hospital key field is:      {0}", hospKey);
                  Console.WriteLine("The vendor key field is:        {0}", vendKey);
                  Console.WriteLine("The exceptions report path is:  {0}", rptPath);
                  Console.WriteLine("The exceptions report name is:  {0}", rptName);
                  Console.WriteLine("The sheet1 tab name is:         {0}", sht1Name);
                  Console.WriteLine("The sheet2 tab name is:         {0}", sht2Name);
              }
          }
      }
  }
  </code></pre>
  
  <p>This works like a champ, but as soon as I try to build it in the Settings, I get nothing back. Here is Settings:</p>
  
  <p><a href="https://i.stack.imgur.com/LcXh4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LcXh4.jpg" alt="Settings image"></a></p>
  
  <p>The created app.config looks perfectly normal:</p>
  
  <p><a href="https://i.stack.imgur.com/E4qXZ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4qXZ.jpg" alt="Renamed to proper application_name.exe.config name"></a></p>
  
  <p>Inside, the contents match the keys and values placed in Settings:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="OHS_RCIS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
          &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" &gt;
              &lt;section name="OHS_RCIS.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
          &lt;/sectionGroup&gt;
      &lt;/configSections&gt;
      &lt;userSettings&gt;
          &lt;OHS_RCIS.Properties.Settings&gt;
              &lt;setting name="Hospkey" serializeAs="String"&gt;
                  &lt;value&gt;invoice_number&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Vendkey" serializeAs="String"&gt;
                  &lt;value&gt;invoice&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Column2" serializeAs="String"&gt;
                  &lt;value&gt;curr_tot_acct_bal&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Column3" serializeAs="String"&gt;
                  &lt;value&gt;COL_AGNCY_NAME&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Column4" serializeAs="String"&gt;
                  &lt;value&gt;admit_date&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Column5" serializeAs="String"&gt;
                  &lt;value&gt;discharge_date&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Column6" serializeAs="String"&gt;
                  &lt;value&gt;create_date&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Column7" serializeAs="String"&gt;
                  &lt;value&gt;HSP_ACCOUNT_ID&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Outpath" serializeAs="String"&gt;
                  &lt;value&gt;C:\events\Reports&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Outname" serializeAs="String"&gt;
                  &lt;value&gt;COB_OB_Advi_Placement_Exceptions_.xlsx&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Hospexcpt" serializeAs="String"&gt;
                  &lt;value&gt;O\'Bleness Exceptions&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Vendexcpt" serializeAs="String"&gt;
                  &lt;value&gt;AdviCare Exceptions&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Tab1Color" serializeAs="String"&gt;
                  &lt;value&gt;FFFFE1FF&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Tab2Color" serializeAs="String"&gt;
                  &lt;value&gt;FFE4E1FF&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="ColumnCount" serializeAs="String"&gt;
                  &lt;value&gt;7&lt;/value&gt;
              &lt;/setting&gt;
          &lt;/OHS_RCIS.Properties.Settings&gt;
      &lt;/userSettings&gt;
      &lt;applicationSettings&gt;
          &lt;OHS_RCIS.Properties.Settings&gt;
              &lt;setting name="Hosppath" serializeAs="String"&gt;
                  &lt;value&gt;C:\events\inbound&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Vendpath" serializeAs="String"&gt;
                  &lt;value&gt;C:\events\outbound&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Hospname" serializeAs="String"&gt;
                  &lt;value&gt;O\'Bleness Exceptions&lt;/value&gt;
              &lt;/setting&gt;
              &lt;setting name="Vendname" serializeAs="String"&gt;
                  &lt;value&gt;AdviCare Exceptions&lt;/value&gt;
              &lt;/setting&gt;
          &lt;/OHS_RCIS.Properties.Settings&gt;
      &lt;/applicationSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The code used to access the app.config looks like this with some added lines trying to coax results:</p>
  
  <pre><code>using System;
  using System.Configuration;
  
  namespace OHS_RCIS.Utility
  {
      public static class ConfigReader
      {
          public static bool ReadAllSettings()
          {
              var success = false;
              ConfigurationManager.GetSection("userSettings");
              ConfigurationManager.RefreshSection("userSettings");
              var appSettings = ConfigurationManager.AppSettings;
  
              if (appSettings.Count &gt; 0)
              {
                  success = true;
              }
              return success;
          }
  
          public static string ReadSetting(string key)
          {
              string result = "";
  
              var appSettings = ConfigurationManager.AppSettings;
              result = appSettings[key] ?? "Not Found";
  
              return result;
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DZEMf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DZEMf.jpg" alt="The calls where it fails in Main()"></a></p>
  
  <p>I am obviously missing something when doing it through Settings, but have the proper references,</p>
  
  <p><a href="https://i.stack.imgur.com/e7BtD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e7BtD.jpg" alt="References"></a></p>
  
  <p>can see the app.config is properly built, and am using the same general code as in my test snippet.</p>
  
  <p><a href="https://i.stack.imgur.com/UFG3G.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UFG3G.jpg" alt="Seen through Debugger"></a></p>
  
  <p>Any clues?</p>