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\mytestservic e.exe.conf ig
When the service attempts to read a string from the config file:
source = ConfigurationManager.AppSe ttings["So urce"].ToS tring();
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?
When the service attempts to read a string from the config file:
source = ConfigurationManager.AppSe
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?
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
Both names match.
It doesn't error with a IOException (FileNotFound) so it looks like it can find the file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Tried both those before and it still doesn't work.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Failed to load configuration file () - Object reference not set to an instance of an object. stack: at SAMS_Document_Transfer.Ser vice1.Star t()
Start() being my function which is actually just called from the Services Start() function.
Start() being my function which is actually just called from the Services Start() function.
i think st. is wrong with your config file
ASKER
Works fine locally
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="ClientSettingsProvide r.ServiceU ri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAut henticatio nMembershi pProvider" >
<providers>
<add name="ClientAuthentication Membership Provider" type="System.Web.ClientSer vices.Prov iders.Clie ntFormsAut henticatio nMembershi pProvider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad3 64e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRol eProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientSer vices.Prov iders.Clie ntRoleProv ider, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad3 64e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
<configuration>
<connectionStrings>
<add name="SAMSConn" connectionString="Data Source=(local);Initial Catalog=SAMS;User ID=sa;Password=x" providerName="System.Data.
</connectionStrings>
<appSettings>
<add key="Source" value="D:\samsDocs\" />
<add key="Destination" value="C:\samsDocs\" />
<add key="ClientSettingsProvide
</appSettings>
<system.web>
<membership defaultProvider="ClientAut
<providers>
<add name="ClientAuthentication
</providers>
</membership>
<roleManager defaultProvider="ClientRol
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientSer
</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\",...
<add key="Source" value="D:\samsDocs\" />
<add key="Destination" value="C:\samsDocs\" />
But in server, you have no more "D:\samsDocs\",...
ASKER
Didn't understand that?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try change mytestservice.exe.config to testservice.exe.config