0

I have two ConfigurationElement objects (one of which is in the running application's app.config) and I need to replace that one with the other. I also have the ConfigurationElementCollection that the first element belongs to. It looks like the Add and Remove methods are protected internal. Is it not intended for me to be able to update the ConfigurationElementCollection object in runtime? If so, what are the alternatives?

Thanks.

user981225
  • 8,762
  • 6
  • 32
  • 41

1 Answers1

2

ConfigurationElementCollection is an abstract class, so the concrete collection class might expose methods to add and remove.

However, when retrieved using the ConfigurationManager.GetSection method configuration is read only so even if the methods were accessible they would not work:

The GetSection method accesses run-time configuration information that it cannot change. To change the configuration, you use the GetSection method on the configuration file that you obtain by using one of the following Open methods:

What do you need to accomplish, and who is consuming that configuration? You might be able to change its behavior at a higher level rather than swapping the configuration information.

fsimonazzi
  • 2,975
  • 15
  • 13
  • What I am trying to do is take two separate app.config files and merge them in runtime. I cannot just deal with an xml merge because whether or not one ConfigurationElement should relace another is based on properties only accessable when those elements are loaded into memory. I would also like to make this as generic as possible (i.e only dealing with the abstract classes) – user981225 Nov 07 '12 at 19:37
  • Who is consuming the configuration, and how? Through ConfigurationManager.GetSection? – fsimonazzi Nov 07 '12 at 19:38
  • I was having a similar issue as the stated question. And was able to resolve it by replacing ConfigurationManager.GetSection(), with ConfigurationManager.OpenExeConfiguration("relevant type I used None because it was the App level").GetSection() – Jackson Enix Jan 07 '19 at 21:54