Duplicate keys in AppConfig do not throw an exception
I discovered this by accident when I have double key / value pairs in my app.config file for a .NET 2.0 console application. To my surprise, it works and the app reads the last pair. I was pulling my hair out trying to figure out why I was unable to get the correct key value (because I didnβt understand that a similar key with the old value was below in the config file).
Sample 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 is, "Wouldn't it be better for the framework to enforce a unique key, throwing an exception at startup, or perhaps a compile-time warning?"
Note. Of course we can't do much with wireframe behavior, we just want some feedback.
+2
source to share