Hi everybody,
I'm woking on a project that requires to extend ConfigurationSection for every configuration object. Configuration information is stored into the database and it can be overriden by custom local configuration. It's the opposite order as I mentioned (local values are merged to database info, proritizing database).
Classed derived from ConfigurationSection are instantiated by reflection. As we know the type associated to a program module, we can just create it, load config info, merge to database and return the object.
Within one of the classes I need to provide another configuration nested, it's a driver that has its own parameters. I thought I could do the following:
public ConfigurationSection DriverConfig {
get { ... }
set { ... }
}
So I can inject by reflection a nested configuration into this one. As I need to decorate the property to indicate where this configuration must be loaded from; I added the following decoration:
[ConfigurationProperty("DriverConfig", IsRequired = false)]
This line causes the object can't be instantiated. I get the following exception:
The Configuration property 'DriverConfig' may not be derived from ConfigurationSection.
I never noted until I tried to set a property by reflection, after create the instance the object is in a "fault" state, all the properties throws same exception.
I'm going to implement it in a different way now, but I would like to know why I'm not able to do that. I know ConfigurationSection is abstract, but I would expect to have the ability to cast a derived object and set this property.
Thanks in advance.