title: Scheduled Console App Crashes with App.config
body: <p>I have a C# console application that reads app settings from its <code>app.config</code>. The console application is targeted as the action of a Windows Scheduler Task. It runs once a day. </p>
  
  <p>Since adding the code to read from the configuration file the app crashes only when run by the Task Scheduler. When run manually (from command prompt or by clicking on it in it's folder)), the application runs with no issues and it works exactly as expected.</p>
  
  <p>Here's the code that reads from the app settings section:</p>
  
  <pre><code>int someValue = 1;
  
  try
  {
      if (ConfigurationManager.AppSettings["someValue"] != null)
          someValue = int.Parse(ConfigurationManager.AppSettings["someValue"].ToString());
  }
  catch(Exception exception)
  {
      // Write to error log
  }
  </code></pre>
  
  <p>This is the exception I'm getting in my error log:</p>
  
  <pre><code>Exception: The type initializer for '&lt;my application name&gt;' threw an exception.
  System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: The parameter 'exePath' is invalid.
  Parameter name: exePath ---&gt; System.ArgumentException: The parameter 'exePath' is invalid.
  Parameter name: exePath
  </code></pre>
  
  <p>I have tried allowing the task to run with highest privileges. I have tried accessing the configuration file in different ways (<code>Configuration.OpenConfigurationExe(...)</code>), etc... I get the same problem every time. I have tried putting my .exe in various locations on disk. This one is in C:\Program Files. I have looked around on S.O. and <a href="https://stackoverflow.com/questions/3283051/exepath-is-invalid-exception-in-configurationmanager-openexeconfiguration">this post</a> suggests that it might be a read permissions issue, but if the task runs under my domain's account and has the highest privileges, is that still possible? Note that it runs just fine if I run it manually from a command prompt or by clicking on it.</p>
  
  <p>How can I reliably get a console application to read its <code>app.config</code> if it has been configured to run under Windows Task Scheduler?</p>