views:

366

answers:

3

Hello,

I have created a C# .net Windows Service that has a config file.

I am reading the settings of the config file from my code using

string setting1 = Properties.Settings.Default.setting1;

If I change the value of setting1 directly in the .config file of the Windows Service for some reason it maintains the value that I had set for it at design time, in the Settings Dialog of the Project.

I do not understand what I am doing wrong ..

Thanks

A: 

Have you restarted the service? I don't think they support dynamic reloading by default.

this question might be helpful or maybe this one

but the gist seems to be to reload the settings using:

Properties.Settings.Default.Reload();

Seeing as its a service you might want to add a FileSystemWatcher to watch the file and call reload when it is changed.

Sam Holder
well, I do set all of the settings in teh config file before starting the service - but it seems to ignore whatever I put in ..
GX
+1  A: 

You have the settings as User scope in place of Application scope.

The user scope settings are in user AppData folder. You can delete it in the AppData folder of the user under whose credentials the windows service runs.

Rohit
no the Scope in the Settings Dialog is set to Application for all settings
GX
A: 

Are you setting the settings in the exe.cofig file or in the app.config from visual studio?

are you having this issue

Sam Holder
All of the Settings have default values - I build the Service - go in the .exe.config file, change the values and start the service -
GX
have you tried debugging the service? you can attach the debugger as shown here: http://stackoverflow.com/questions/1914296/how-to-debug-windows-service-which-fails-in-init-method/1914318#1914318 you might also want to try using procmon http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx to determine which file the service is reading when it starts up.
Sam Holder