Updating ConfigurationSection in the Configuration

Topics: General discussion
Mar 13, 2008 at 3:46 PM
Edited Mar 13, 2008 at 3:49 PM
I am using Configuration Data spanned across multiple config files. I want to update configuration data. When i run it i got the following InvalidOperationExeption i.e. Cannot add a Configuration Section that already belongs to the Configuration

Here is the code snippet
FileConfigurationSource fcs = new FileConfigurationSource(@"C:\ConfigBlockTesting1\bin\Debug\ConfigBlockTesting1.vshost.exe.config");
MyCustomSection mySection = MyCustomSection.GetSection(fcs);
FileConfigurationParameter fcp = new FileConfigurationParameter(@"C:\ConfigBlockTesting1\bin\Debug\ConfigBlockTesting1.vshost.exe.config");

mySection.FirstValue = 10;
mySection.SecValue = "Abc";

fcs.Add(fcp, "myCustomSection", mySection);//exception at this line

Can anybody tell me how can i update the config file......