I have custom section Links which I Should edit from UI. While saving I couldn't save the value of the corresponding key. It shows "collection is read only" error. Please help me to resolve this. Thanks in Advance.
WebConfig
- <sectionGroup name="Menu">
- <section name="Links" type="System.Configuration.NameValueSectionHandler"/>
- sectionGroup>
C#
- NameValueCollection nameValueCol = (NameValueCollection)ConfigurationManager.GetSection("Menu/Links");
- var Key = "Key";
- var Value = "Value";
- nameValueCol.Set(Key, Value); // Error: collection is read only
so I tried to remove and add the keys still it shows same error.
- nameValueCol.Remove(Key); // Error: collection is read only
- nameValueCol.Add(Key, Value);

Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 15, 2016, 12:49 AM EDT
Hi Amir,
Please find the below link.
Amir Krish4 reputationPosted Mar 15, 2016, 3:00 AM EDT
Rajeev PunhaniRank #551 · 4.4K reputationPosted Mar 15, 2016, 3:41 AM EDT
Hi Amir,
you can edit those values but those won't be reflected in web.config if you open it until application is restarted.If application is restarted you sessions will be lost.
If the above solution is helpful then,accept the answer.