is it a bug for the GetValues in System.Configuration.ConfigurationSettings.AppSettings

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Hello" value="World 1" />
<add key="Hello" value="World 2" />
<add key="Hello" value="World 3" />
</appSettings>
</configuration>

the System.Configuration.ConfigurationSettings.AppSettings.GetValues
only return a string[] with only 1 element of value "World 3"...

bug or i used it wrongly?!

thx...
 
I also tried the TraceSwitch...also didn't work...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="mySwitch" value="2" />
</switches>
</system.diagnostics>
</configuration>

Then i create an instance by
TraceSwitch mySwitch = new TraceSwitch("Test", "Testing");

the mySwitch.Level is still Off

it seems that it is the problem of the one who wrote the classes in
System.Diagnostics ...
 
sorry, my mistake
i should use "Test" instead of "mySwitch"



babylon said:
I also tried the TraceSwitch...also didn't work...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<switches>
<add name="mySwitch" value="2" />
</switches>
</system.diagnostics>
</configuration>

Then i create an instance by
TraceSwitch mySwitch = new TraceSwitch("Test", "Testing");

the mySwitch.Level is still Off

it seems that it is the problem of the one who wrote the classes in
System.Diagnostics ...



babylon said:
here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Hello" value="World 1" />
<add key="Hello" value="World 2" />
<add key="Hello" value="World 3" />
</appSettings>
</configuration>

the System.Configuration.ConfigurationSettings.AppSettings.GetValues
only return a string[] with only 1 element of value "World 3"...

bug or i used it wrongly?!

thx...
 
This is expected and documented behavior. You cannot have multiple keys with
the same name.

Jerry
 
then...
what's the different between Get and GetValues?
Get suppose for a key with ONE value, so it return string.
GetValues return string[], which should return a list of values...but only
[0] is valid....
so strange...

Jerry III said:
This is expected and documented behavior. You cannot have multiple keys with
the same name.

Jerry

babylon said:
here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Hello" value="World 1" />
<add key="Hello" value="World 2" />
<add key="Hello" value="World 3" />
</appSettings>
</configuration>

the System.Configuration.ConfigurationSettings.AppSettings.GetValues
only return a string[] with only 1 element of value "World 3"...

bug or i used it wrongly?!

thx...
 
Well, the collection holding the keys allows for multiple values per key but
the configuration section handler that reads the configuration and stores it
in the collection doesn't.

Jerry

Action said:
then...
what's the different between Get and GetValues?
Get suppose for a key with ONE value, so it return string.
GetValues return string[], which should return a list of values...but only
[0] is valid....
so strange...

Jerry III said:
This is expected and documented behavior. You cannot have multiple keys with
the same name.

Jerry

babylon said:
here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Hello" value="World 1" />
<add key="Hello" value="World 2" />
<add key="Hello" value="World 3" />
</appSettings>
</configuration>

the System.Configuration.ConfigurationSettings.AppSettings.GetValues
only return a string[] with only 1 element of value "World 3"...

bug or i used it wrongly?!

thx...
 
The AppSettings section uses a NameValueCollection section handler. That
particular configuration doesn't support multiple keys. You could create
your own section handler, and add configuration information with multiple
keys, outside of appSettings. You would then find GetValues useful.


Action said:
then...
what's the different between Get and GetValues?
Get suppose for a key with ONE value, so it return string.
GetValues return string[], which should return a list of values...but only
[0] is valid....
so strange...

Jerry III said:
This is expected and documented behavior. You cannot have multiple keys with
the same name.

Jerry

babylon said:
here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Hello" value="World 1" />
<add key="Hello" value="World 2" />
<add key="Hello" value="World 3" />
</appSettings>
</configuration>

the System.Configuration.ConfigurationSettings.AppSettings.GetValues
only return a string[] with only 1 element of value "World 3"...

bug or i used it wrongly?!

thx...
 
Back
Top