What I ended up doing because this was the path of least resistance was use the built-in Configuration classes in the .NET Fx. Even though the below code is in C# you should be able to convert it to VB.NET with little difficulty (or edit and compile it into an assembly you can reference from your project).
You will note that the ConfigurationElementCollection class can be converted into a dictionary of key/value pairs with little difficulty (you may have to use reflection for the value pairs or the classes you want to store as value pairs could take settings classes that inherit from ConfigurationElement as a constructor argument).
// ConfigurationElement.cs
public class ConfigurationElement : System.Configuration.ConfigurationElement
{
protected T GetValue<T>(string key, T defaultValue)
{
var value = default(T);
if (base[key] != null)
{
var str = base[key].ToString();
try
{
if (!String.IsNullOrEmpty(str))
value = (T)Convert.ChangeType(str, typeof(T));
}
catch // use the default
{
}
}
return value;
}
}
// ConfigurationElementCollection.cs
public abstract class ConfigurationElementCollection<TElement,TKey> :
ConfigurationElementCollection,
IEnumerable<TElement> where TElement : System.Configuration.ConfigurationElement, new()
{
public TElement this[int index]
{
get { return (TElement)BaseGet(index); }
}
public TElement this[TKey key]
{
get { return (TElement)BaseGet(key); }
}
protected override System.Configuration.ConfigurationElement CreateNewElement()
{
return new TElement();
}
protected override object GetElementKey(System.Configuration.ConfigurationElement element)
{
return GetElementKey((TElement)element);
}
protected abstract TKey GetElementKey(TElement element);
public TKey[] GetAllKeys()
{
var keys = BaseGetAllKeys();
var ret = new TKey[keys.Length];
for (var i = 0; i < keys.Length; i++)
ret[i] = (TKey)keys[i];
// done
return ret;
}
public void Add(TElement element)
{
BaseAdd(element);
}
public void Remove(TElement element)
{
BaseRemove(element);
}
public void Clear()
{
BaseClear();
}
IEnumerator<TElement> IEnumerable<TElement>.GetEnumerator()
{
foreach (TElement element in this)
{
yield return element;
}
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
throw new System.NotImplementedException();
}
}
And here's an example where I use the above base class code for our sharding strategy in our system (names altered to protect the innocent):
<!-- web.config -->
<!-- ... -->
<configuration>
<configSections>
<section name="sharding" type="Domain.ShardingSection, Domain.Configuration" />
</configSections>
</configuration>
<!-- ... -->
<sharding>
<configurationMappings>
<add lastDigit="0" sqlMapFileName="Shard-0.SqlMap.config" />
<add lastDigit="1" sqlMapFileName="Shard-1.SqlMap.config" />
<add lastDigit="2" sqlMapFileName="Shard-2.SqlMap.config" />
<add lastDigit="3" sqlMapFileName="Shard-3.SqlMap.config" />
<add lastDigit="4" sqlMapFileName="Shard-4.SqlMap.config" />
<add lastDigit="5" sqlMapFileName="Shard-5.SqlMap.config" />
<add lastDigit="6" sqlMapFileName="Shard-6.SqlMap.config" />
<add lastDigit="7" sqlMapFileName="Shard-7.SqlMap.config" />
<add lastDigit="8" sqlMapFileName="Shard-8.SqlMap.config" />
<add lastDigit="9" sqlMapFileName="Shard-9.SqlMap.config" />
</configurationMappings>
</sharding>
And then the configuration classes represented by the XML instance above:
// ShardElement.cs
public class ShardElement : ConfigurationElement
{
[ConfigurationProperty("lastDigit", IsKey=true, IsRequired=true)]
public int LastDigit
{
get { return (int)this["lastDigit"]; }
}
[ConfigurationProperty("sqlMapFileName", IsRequired=true)]
public string SqlMapFileName
{
get { return (string)this["sqlMapFileName"]; }
}
}
// ShardElementCollection.cs
public class ShardElementCollection : ConfigurationElementCollection<ShardElement, int>
{
protected override int GetElementKey(ShardElement element)
{
return element.LastDigit;
}
}
// ShardingSection.cs
public class ShardingSection : ConfigurationSection
{
public const string Name = "sharding";
[ConfigurationProperty("configurationMappings")]
public ShardingElementCollection ConfigurationMappings
{
get { return (ShardingElementCollection)base["configurationMappings"]; }
}
}
While its not true IDictionary in a *.config file it can handle the job, and if your configuration file is updated at runtime you don't have to restart the application or recycle the AppPool to get the new values.