I have this strange problem ... in my code, if I set the IsRequired value to false or true, then it remains false. However, if I entered DefaultValue, does it work?
Inoperative code:
public class FtpSettingsSection : ConfigurationSection { [ConfigurationProperty("host", IsRequired = true)] public HostElement Host { get { return (HostElement)this["host"]; } set { this["host"] = value; } } } public class HostElement : ConfigurationElement { [ConfigurationProperty("URL", IsRequired = true)] public string URL { get { return (string)this["URL"]; } set { this["URL"] = value; } } }
and working code:
public class FtpSettingsSection : ConfigurationSection { [ConfigurationProperty("host", DefaultValue = "", IsRequired = true)] public HostElement Host { get { return (HostElement)this["host"]; } set { this["host"] = value; } } } public class HostElement : ConfigurationElement { [ConfigurationProperty("URL", DefaultValue = "", IsRequired = true)] public string URL { get { return (string)this["URL"]; } set { this["URL"] = value; } } }
Why do I need to set DefaultValue to ""?
c # config configuration
ebb
source share