The Last Configuration Section Handler

I stumbled across the Craig Andera post The Last Configuration Section Handler I'll Ever Need a few months ago, but I didn't really understand the implications until I started writing a bunch of configuration section handlers. His approach is very clever; instead of writing a bunch of tedious code to read settings from a .config file, you deserialize an instance of the class using the .config file XML as the input!

This is a companion discussion topic for the original blog entry at:

I wonder if there is any way to do the same thing with a typed dataset. For some reason, I would feel more comfortable pulling data out of a typed data set than a class. (Although there is probably not much difference, I would prefer to not use reflection.) Could you just duplicate the types, then do a Dataset.ReadXml on the node?

  • Joshua

Dunno, but it’s a fine idea. Care to test it out?

Scott Weinstein has an update on this class:

I am new to the many uses/advantages with an app.config file. I tried implementing the above code as an initial test and it doesn’t appear to work for me.

I am sure there are details that are assumed. Can someone explain what ‘MyClass’ refers to within the config file and also the one line that casts the config settings to an object?

Thanks in advance!

Download a newer version of this code, in your choice of C# or VB.NET, here:

Do you have a VB version of this very useful function that does not use the deprecated IConfigurationSectionHandler ? I hve been trying without success to create one.
Thanks !