Link to home
Start Free TrialLog in
Avatar of Type25
Type25

asked on

Reading config file from windows service

I've added a config file to my windows service and it resides in the directory where the service exists, ie. "C:\myservice\testservice.exe   and "C:\myservice\mytestservice.exe.config

When the service attempts to read a string from the config file:

source = ConfigurationManager.AppSettings["Source"].ToString();

it errors with: Path is not of legel form  

Doesn't matter what data is in source it still errors with that.

What am i doing wrong?
Avatar of rambovn
rambovn
Flag of Germany image

"C:\myservice\testservice.exe   and "C:\myservice\mytestservice.exe.config
try change mytestservice.exe.config to testservice.exe.config


Avatar of Type25
Type25

ASKER

Sorry, that was just an example, it's called something completely different.
Both names match.

It doesn't error with a IOException (FileNotFound) so it looks like it can find the file
ASKER CERTIFIED SOLUTION
Avatar of Gyanendra Singh
Gyanendra Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Type25

ASKER

Tried both those before and it still doesn't work.

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Type25

ASKER

Failed to load configuration file () - Object reference not set to an instance of an object. stack:    at SAMS_Document_Transfer.Service1.Start()

Start() being my function which is actually just called from the Services Start() function.
i think st. is wrong with your config file
Avatar of Type25

ASKER

Works fine locally
Avatar of Type25

ASKER

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="SAMSConn" connectionString="Data Source=(local);Initial Catalog=SAMS;User ID=sa;Password=x" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="Source" value="D:\samsDocs\" />
    <add key="Destination" value="C:\samsDocs\" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=3.5.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=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>
Local machine you have the value right -> work
    <add key="Source" value="D:\samsDocs\" />
    <add key="Destination" value="C:\samsDocs\" />
But in server, you have no more "D:\samsDocs\",...
Avatar of Type25

ASKER

Didn't understand that?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial