title: Windows service not getting values from App.config
body: <p>I created simple windows service as below:</p>
  
  <pre><code>   private void TraceService(string content)
          {
              try
              {
                  string path = ConfigurationManager.AppSettings["TextLocation"];
  
                  FileStream fs = new FileStream(@path, FileMode.OpenOrCreate, FileAccess.Write);
                  StreamWriter sw = new StreamWriter(fs);             
                  sw.BaseStream.Seek(0, SeekOrigin.End);                
                  sw.WriteLine(content);         
                  sw.Flush();             
                  sw.Close();
              }
              catch (Exception ex)
              {
                  FileStream fs = new FileStream(@"D:\Error.txt", FileMode.OpenOrCreate, FileAccess.Write);            
                  StreamWriter sw = new StreamWriter(fs);              
                  sw.BaseStream.Seek(0, SeekOrigin.End);               
                  sw.WriteLine(ex.Message);
                  sw.Flush();               
                  sw.Close();
              }
          }
  </code></pre>
  
  <p>if I run this service in VS command prompt using <strong>Installutil</strong> then it gets the value from app.config. but i need to create installer using <a href="http://wixtoolset.org/" rel="nofollow">wixInstaller</a>. when i run the installer and start service it throws an exception and message saved as <strong>"Path cannot be null."</strong> What is the reason for this? How can i solve this?</p>
  
  <p><strong>EDIT</strong>: My App.config as below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="TextLocation" value="d:\ScheduledServiceNew.txt"/&gt;
    &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>my Wix Installer File :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"&gt;
      &lt;Product Id="5AC767F2-4F21-45DF-9DAB-C013C62B2B67" Name="Installer" Language="1033" Version="1.0.0.0" Manufacturer="TRT " UpgradeCode="3fd83540-23f6-45f4-bb1c-e77c12725680"&gt;
          &lt;Package InstallerVersion="200" Compressed="yes" /&gt;
          &lt;Media Id="1" Cabinet="SampleApp.cab" EmbedCab="yes" /&gt;
          &lt;Directory Id="TARGETDIR" Name="SourceDir"&gt;
              &lt;Directory Id="ProgramFilesFolder"&gt;
                  &lt;Directory Id="INSTALLFOLDER" Name="Installer"&gt;
                      &lt;Directory Id="TestService" Name="TestService"&gt;
                          &lt;Component Id="MainExecutable" Guid="CE30D5D8-3211-4890-A9DC-0C315C15B39E"&gt;
                              &lt;File Id="testServiceexe" Name="TestInstallerProject.exe" DiskId="1" KeyPath="yes" Source="..\TestInstallerProject\bin\Debug\TestInstallerProject.exe" /&gt;
                              &lt;File Id="App.config" Name="App.config" Source="..\TestInstallerProject\App.config" /&gt;
                              &lt;ServiceInstall Name="ScheduledService" Type="ownProcess" Start="auto" ErrorControl="ignore" Id="ServiceInstaller" DisplayName="ScheduledService" Account="[SERVICEACCOUNT]" Password="[SERVICEACCOUNTPASSWORD]"&gt;
                                  &lt;util:ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="restart" ResetPeriodInDays="1" RestartServiceDelayInSeconds="1" /&gt;
                              &lt;/ServiceInstall&gt;
                              &lt;ServiceControl Id="StartService" Name="ScheduledService" Start="install" Stop="both" Remove="uninstall" Wait="no" /&gt;
                              &lt;RemoveFolder Id="INSTALLDIR" On="uninstall" /&gt;
                          &lt;/Component&gt;
                      &lt;/Directory&gt;
                  &lt;/Directory&gt;
              &lt;/Directory&gt;
          &lt;/Directory&gt;
          &lt;Feature Id="Complete" Title="Installer" Level="1"&gt;
              &lt;ComponentRef Id="MainExecutable" /&gt;
          &lt;/Feature&gt;
          &lt;UI /&gt;
      &lt;/Product&gt;
  &lt;/Wix&gt;
  </code></pre>