- TypeConverter converter = TypeDescriptor.GetConverter (targetType);
- return converter.ConvertFrom (GetAppSetting (key));
- }
- catch (NotSupportedException e) {
- throw new InvalidOperationException (String.Format ("Could not convert app setting {0} to type {1}", key, targetType));
+ TypeConverter converter = TypeDescriptor.GetConverter (pi.PropertyType);
+ return converter.ConvertFrom (value);
+ } catch (NotSupportedException) {
+ throw new InvalidOperationException (String.Format (
+ "Could not convert application setting '{0}' " +
+ " to type '{1}' for property '{2}'.", value,
+ pi.PropertyType.Name, pi.Name));