views:

190

answers:

1

I discovered this by chance when I have a duplicate key/value pairs in my app.config file for a .NET 2.0 console app. To my surprise, it works and the app reads the latest pair. I was pulling my hair when trying to figure out why I could not fetch the correct value of a key (cause I did not realise a similar key with an old value was lower down in the config file).

Example of the config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
        <add key="key1" value="val1"/>
        <add key="key1" value="val2"/>
    </appSettings>
</configuration>

My question: Isn't it 'better' that the framework be enforcing unique key by throwing an exception during startup or perhaps a warning during compilation?

Note: Of course we can't really do much about the framework behaviour, just want to get some feedbacks.

+1  A: 

It seems that it's behaving like this on purpose (to support multiple values for same key) Here's an article that I found.

Beatles1692
Considering mine wasn't a typical question, I'll take this for an answer.
o.k.w