I have a windows service that is referencing another assembly (class library). In this other assembly I used Application Settings to store some values. When I copy all the required files to the server I can see these settings in AssemblyName.dll.config file.
However, when I change a setting in this config file and restart the service the change has no effect. Even if I uninstall/reinstall the service it still returns the old value at runtime.
Config file:
<setting name="RecordLimit" serializeAs="String">
<value>300</value>
</setting>
Code:
if (recordCount > Settings.Default.RecordLimit) //always 300
So even if I change the value in the config file to 400 and restart or even reinstall the service, the value is always 300 making me think that this value is stored in and returned from the compiled code.
What am I doing wrong and is it possible that changes to application settings always require a recompile and reinstall (I understand that I can use Save()
method to change the settings from code but this is a windows service so using this method doesn't seem to make sense)?
If these settings stored in the config file have no effect and the settings are stored in the compiled code, can I safely remove these config files?
If these settings cannot be changed without recompiling what other options I have to store setting that I can change without recompling?
EDIT: I just removed the AssemblyName.dll.config file and the code returned 300 so the config file is irrelevant apparently.
As far as I know how config files work, it has to be at the EXE level: appname.exe.config for services/apps and web.config for web sites/services.
See question/answers at Can someone provide a quick App.config/Web.config tutorial? for reference.
Can the exe that references the DLL manipulate the configuration settings in its own config?
You should try adding the settings to the exe.config as a test.
I think it might be that the .config.dll file that is actually being used is somewhere in C:\Users\Username\AppData (in Win7). Try searching for AssemblyName.dll in that folder, and enough looking around should find it.
来源:https://stackoverflow.com/questions/11352465/changing-net-application-settings-without-recompiling