• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Write to XML configuration File in C#

JoeCDaMan

Senior member
I want to write to an XML configuration file but I get an error message saying the following:

code: System.Configuration.ConfigurationSettings.AppSettings("compNameConf") = "some string value"

message: "An unhandled exception of type 'System.NotSupportedException' occurred in system.dll
Additional information: Collection is read-only."

I am reading the file ok, with this code:

string str;

str = System.Configuration.ConfigurationSettings.AppSettings("compNameConf")

How do I alleviate this problem?

Thanks
 
Well, the configuration file is Read-Only... they simply don't allow you to modify it. You could get around this by opening the file directly and then use XML reader/writer to make changes.

So since you gotta do all that work I just abandoned that file and created a simple INI file in IsolatedStorage to store my app's settings which get updated every once in a while
 
if this is a web app then you should not do this unless you don't mind the app restarting every time you make the change. if it's a forms app it should be ok.
 
if this is a web app then you should not do this unless you don't mind the app restarting every time you make the change. if it's a forms app it should be ok.

Technically you don't need to restart the web app, you just need to refresh the cache and pick up any changes you made to the .config
 
Originally posted by: JoeCDaMan
if this is a web app then you should not do this unless you don't mind the app restarting every time you make the change. if it's a forms app it should be ok.

Technically you don't need to restart the web app, you just need to refresh the cache and pick up any changes you made to the .config

I don't think you are following. If you alter the web.config file in a web application, it will restart with or without your permission.
 
Back
Top