I have the following node in my web.config
<parameter value="100" type="System.Int64, mscorlib" />
which is read into the following ConfigurationProperty
public class ParameterElement : ConfigurationElement
{
[ConfigurationProperty("type", IsRequired = false, DefaultValue = "System.String, mscorlib")]
[TypeConverter(typeof (TypeNameConverter))]
public Type Type
{
get { return (Type) this["type"]; }
set { this["type"] = value; }
}
[ConfigurationProperty("value", IsRequired = true)]
public object Value
{
get { return ... ? }
set { this["value"] = value; }
}
}
This is correctly establishing the Type that I've set on the node, but how can I return the value in that type? Everything that I've tried returns the following exception:
Unable to find a converter that supports conversion to/from string for the property 'value' of type 'Object'.
It may be too late, but I had the same need and i found a solution.
First you need to add a TypeConverter on Value to deserialize the configuration, I choose StringConverter but we could implement a XMLConverter or a JSONConverter.
Second, you must parse the string, xml or json
Here my extension method to parse the string