Note that there are some explanatory texts on larger screens.

plurals
  1. POUnrecognized element "Item" in config file with custom config section
    primarykey
    data
    text
    <p>I have a custom config which is based on some classes. My problem is that I get an error saying that a config element is unrecognized. The class is as follows:</p> <pre><code>[ConfigurationCollection(typeof(SectionItem), AddItemName = "Item", CollectionType = ConfigurationElementCollectionType.BasicMap)] public class Sections : ConfigurationElementCollection { public SectionItem this[int index] { get { return BaseGet(index) as SectionItem; } set { if (BaseGet(index) != null) { BaseRemoveAt(index); } BaseAdd(index, value); } } public new SectionItem this[string response] { get { return (SectionItem)BaseGet(response); } set { if (BaseGet(response) != null) { BaseRemoveAt(BaseIndexOf(BaseGet(response))); } BaseAdd(value); } } protected override ConfigurationElement CreateNewElement() { return new SectionItem(); } protected override object GetElementKey(ConfigurationElement element) { return ((SectionItem)element).Key; } } </code></pre> <p>And the <code>SectionItem</code> class:</p> <pre><code>public class SectionItem : ConfigurationElement { [ConfigurationProperty("key", IsRequired = true, IsKey = true)] public string Key { get { return this["key"] as string; } } } </code></pre> <p>If I add a configuration property of type <code>SectionItems</code> in the <code>Sections</code> class that won't work for me, because I want to have multiple <code>SectonItems</code> inside the <code>Section</code> tag in the config file. I've searched for solutions but everything I've found didn't do the trick with this. For a better understanding of what I'm trying to achieve this is how my config looks:</p> <pre><code>&lt;configuration&gt; &lt;configSections&gt; &lt;section name="AdminConfig" type="XmlTest.AdminConfig, XmlTest"/&gt; &lt;/configSections&gt; &lt;startup&gt; &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt; &lt;/startup&gt; &lt;AdminConfig&gt; &lt;Field name="field1" key="12345" path="asd"/&gt; &lt;Section&gt; &lt;Item key="12345"/&gt; &lt;Item key="54321"/&gt; &lt;/Section&gt; &lt;/AdminConfig&gt; &lt;/configuration&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload