Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing .NET application settings without recompiling

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.

like image 653
Dean Kuga Avatar asked Jul 05 '12 20:07

Dean Kuga


People also ask

Where are .NET application settings stored?

settings file that the project system creates; this file is the default file that the Project Designer displays in the Settings tab. Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects.

Does .NET Core require web config?

The web. config file is required at the root of the app to enable the publishing of multiple apps using Web Deploy.

Does .NET Core use app config?

Application configuration in ASP.NET Core is performed using one or more configuration providers. Configuration providers read configuration data from key-value pairs using a variety of configuration sources: Settings files, such as appsettings. json.

Is app config the same as web config?

The web. config file is required for ASP.NET webpages. The app. config file is optional in an application and doesn't have to be used when writing desktop applications.


1 Answers

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.

like image 88
Jesse C. Slicer Avatar answered Sep 22 '22 15:09

Jesse C. Slicer