c# - update app.config file at runtime -


i trying update app.config file @ runtime. error

system.nullreferenceexception: object reference not set instance of object. line 59.

what trying change url @ runtime, having pop form has textbox used url, used update config file.

public void changesettings()     {         configuration config =             configurationmanager.openexeconfiguration(configurationuserlevel.none);             keyvalueconfigurationcollection settings = config.appsettings.settings;          try         {             console.writeline("nothing " + configurationmanager.appsettings["client_postcoderef_service"]);             settings["client_postcoderef_service"].value = textbox1.text; <- line 59             config.save(configurationsavemode.modified);             configurationmanager.refreshsection("applicationsettings");             console.writeline("nothing 2 " + configurationmanager.appsettings["client_postcoderef_service"]);         }         catch (configurationerrorsexception e)         {             messagebox.show("[exception error: {0}]",                 e.tostring());         }         } 

here config file

 <applicationsettings >     <client.properties.settings>       <setting name="client_postcoderef_service" serializeas="string">         <value>http://127.0.0.1/directory/directory/webservice.asmx</value>       </setting>       </client.properties.settings>     </applicationsettings> 

you using applicationsettings not appsettings.
2 different sections of config file.

to use entry in applicationsettings use syntax:

string result = client.properties.settings.default.client_postcoderef_service; 

also note can't change value of applicationsetting entry inside program.
detailed discussion on pros , cons of applicationsettings , appsettings can found here


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -