Duplicate keys in appSettings in App.Config
-
Saturday, March 24, 2007 4:12 PM
If I have the following xml in my App.Config
<appSettings>
<add key="Key" value="Value1" />
<add key="Key" value="Value2" />
</appSettings>then calling ConfigurationManager.AppSettings.GetValues("Key") returns an array of strings with only one entry -- the last entry in in the appSettings ("Value2").
There was a useful article written on how to get this to work on CodeProject (http://www.codeproject.com/dotnet/namevaluemultiple.asp), but that doesn't seem to work with .net 2.0 (I get a run-time exception that the appsettings section can't be modified).
Does anyone know of a sample somewhere on how to get this to work in .net 2.0?
All Replies
-
Monday, July 07, 2008 1:49 AM
I get around this these days by doing:
<appSettings>
<add key="Key" value="Value1|Value2" />
</appSettings>
Or whatever else makes sense as a delimiter instead of | . Then I just use String.Split() to break down the value string into an array of strings.
/\/\}{- Marked As Answer by MuscleHead Tuesday, July 15, 2008 2:11 AM
-
Tuesday, February 16, 2010 7:57 PM
Ran into same thing, this is clearly A BUG not a feature.
The function GetValues says it returns a string array and compiles as such.
We're not getting an array, just a scalar, so it's a bug.
Faking an array by manually putting delimiters in a single string and doing a split, is still just getting a single string from the function.
It's a bug.
Microsoft, please fix. -
Thursday, March 17, 2011 11:42 AM
And its a bug that's been around for donkeys years.
Microsoft please fix

