I'm holding a custom configuration section in machine.config of following structure:
<CustomSettings>
<add key="testkey" local="localkey1" dev="devkey" prod="prodkey"/>
</CustomSettings>
Now, i want to be able to override the same key settings by storing the overrides in app.config like this:
<CustomSettings>
<add key="testkey" dev="devkey1" prod="prodkey1"/>
</CustomSettings>
So that when i read it in code i'll get - dev="devkey1", prod="prodkey1", local="localkey1"
Problem is that when i read my custom config section like this:
CustomConfigurationSection section = ConfigurationManager.GetSection("CustomSettings") as CustomConfigurationSection;
i get an error stating that the key has already been added:
"The entry 'testkey' has already been added."
I modified making the ConfigElementCollection.Add function to check if the same key already exists but it didn't work.
Any ideas?
I ended up overriding BaseAdd in the ConfigurationElementCollection:
I hope it helps...