S
shapper
Hello,
I am trying to get a custom configuration section as follows:
EnvironmentConfigurationSection environment =
System.Configuration.ConfigurationManager.GetSection("environment") as
EnvironmentConfigurationSection;
But I keep getting the same error:
The Configuration property 'Cdn' may not be derived from
ConfigurationSection
Can someone tell me what am I doing wrong? My code is the following:
public partial class EnvironmentConfigurationSection :
ConfigurationSection {
[ConfigurationProperty("Cdn")]
public CdnConfigurationSection Cdn { get { return this["Cdn"] as
CdnConfigurationSection; } }
} // EnvironmentConfigurationSection
public class CdnConfigurationSection : ConfigurationSection {
[ConfigurationProperty("google", IsRequired = true, IsKey = false,
IsDefaultCollection = true)]
public CdnGoogleConfigurationElementCollection Google { get { return
this["google"] as CdnGoogleConfigurationElementCollection; } }
} // CdnConfigurationSection
public class CdnGoogleConfigurationElementCollection :
ConfigurationElementCollection {
[ConfigurationProperty("key", IsRequired = true)]
public String Key { get { return this["key"] as String; } } // Key
public CdnGoogleConfigurationElement this[Int32 index] {
get {
return base.BaseGet(index) as CdnGoogleConfigurationElement;
}
set {
if (base.BaseGet(index) != null) {
base.BaseRemoveAt(index);
}
this.BaseAdd(index, value);
}
} // CdnGoogleConfigurationElement
protected override ConfigurationElement CreateNewElement() {
return new CdnGoogleConfigurationElement();
} // CreateNewElement
protected override Object GetElementKey(ConfigurationElement
element) {
return ((CdnGoogleConfigurationElement)element).Name;
} // GetElementKey
} // CdnGoogleConfigurationElementCollection
public class CdnGoogleConfigurationElement : ConfigurationElement {
[ConfigurationProperty("name", IsRequired = true)]
public String Name { get { return this["name"] as String; } }
[ConfigurationProperty("version", IsRequired = true)]
public String Version { get { return this["version"] as String; }}
} // CdnGoogleConfigurationElement
Thank You,
Miguel
I am trying to get a custom configuration section as follows:
EnvironmentConfigurationSection environment =
System.Configuration.ConfigurationManager.GetSection("environment") as
EnvironmentConfigurationSection;
But I keep getting the same error:
The Configuration property 'Cdn' may not be derived from
ConfigurationSection
Can someone tell me what am I doing wrong? My code is the following:
public partial class EnvironmentConfigurationSection :
ConfigurationSection {
[ConfigurationProperty("Cdn")]
public CdnConfigurationSection Cdn { get { return this["Cdn"] as
CdnConfigurationSection; } }
} // EnvironmentConfigurationSection
public class CdnConfigurationSection : ConfigurationSection {
[ConfigurationProperty("google", IsRequired = true, IsKey = false,
IsDefaultCollection = true)]
public CdnGoogleConfigurationElementCollection Google { get { return
this["google"] as CdnGoogleConfigurationElementCollection; } }
} // CdnConfigurationSection
public class CdnGoogleConfigurationElementCollection :
ConfigurationElementCollection {
[ConfigurationProperty("key", IsRequired = true)]
public String Key { get { return this["key"] as String; } } // Key
public CdnGoogleConfigurationElement this[Int32 index] {
get {
return base.BaseGet(index) as CdnGoogleConfigurationElement;
}
set {
if (base.BaseGet(index) != null) {
base.BaseRemoveAt(index);
}
this.BaseAdd(index, value);
}
} // CdnGoogleConfigurationElement
protected override ConfigurationElement CreateNewElement() {
return new CdnGoogleConfigurationElement();
} // CreateNewElement
protected override Object GetElementKey(ConfigurationElement
element) {
return ((CdnGoogleConfigurationElement)element).Name;
} // GetElementKey
} // CdnGoogleConfigurationElementCollection
public class CdnGoogleConfigurationElement : ConfigurationElement {
[ConfigurationProperty("name", IsRequired = true)]
public String Name { get { return this["name"] as String; } }
[ConfigurationProperty("version", IsRequired = true)]
public String Version { get { return this["version"] as String; }}
} // CdnGoogleConfigurationElement
Thank You,
Miguel