For ConfigurationProperty to work, the type used must be associated with a TypeConverter , than to know how to convert from a string. ConfigurationProperty has a Converter property, but, alas, it is read-only. And, really bad luck, the version does not have an implicit TypeConverter declared either.
What you can do is add TypeConverterAttribute to the version class programmatically, and this will do about all these issues. Therefore, you need to basically call this line once in your program before accessing the configuration:
TypeDescriptor.AddAttributes(typeof(Version), new TypeConverterAttribute(typeof(VersionTypeConverter)));
with the following custom VersionTypeConverter:
public class VersionTypeConverter : TypeConverter { public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { return new Version((string)value); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) return true; return base.CanConvertFrom(context, sourceType); } }
source share