title: Multiple Elements in Custom ConfigurationSection
body: <p><strong>UPDATE</strong>: Custom Configs are freaking HARD! >.&lt; While I've learned some things about XML; evidently it's impossible to store CDATA in an element, so I've rephrased this question to fit the modified structure. Please ask me any questions for clarity. I've been working on this issue for around a month off and on and keep running into various issues.</p>
  
  <p>I've been follow the MSDN example in the article referenced below, but I'm have trouble applying the concept to my case. My project is a VB.NET 4.0 Web Application in VS2010, but answers in C# are alright as well (as long as the solution will work in VB). :) Here's the relevant code:</p>
  
  <p><strong>Call</strong>:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim conf As ApiSection = CType(ConfigurationManager.GetSection("remoteServiceApi/site"), ApiSection)
  </code></pre>
  
  <p><strong>Exception</strong> (ConfigurationErrorsException)</p>
  
  <pre class="lang-none prettyprint-override"><code>The element &lt;site&gt; may only appear once in this section.
  </code></pre>
  
  <p>Please note the following relevant code...</p>
  
  <p><strong>Schema</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;xs:element name="ApiSection"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="site" id="environment" nillable="false" maxOccurs="unbounded"&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:attribute name="environment" use="required"&gt;
                          &lt;xs:simpleType&gt;
                              &lt;xs:restriction base="xs:string"&gt;
                                  &lt;xs:enumeration value="Production"&gt;&lt;/xs:enumeration&gt;
                                  &lt;xs:enumeration value="Sandbox"&gt;&lt;/xs:enumeration&gt;
                              &lt;/xs:restriction&gt;
                          &lt;/xs:simpleType&gt;
                      &lt;/xs:attribute&gt;
                      &lt;xs:attribute name="APIKey" type="xs:string" use="required" /&gt;
                      &lt;xs:attribute name="APIUsername" type="xs:string" use="required" /&gt;
                      &lt;xs:attribute name="APIPassword" type="xs:string" use="required" /&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>Even though I added and activated the above in the schema set for the web.config file, it does not seem to be actually working. :( Could this be the issue?</p>
  
  <p><strong>Web.Config</strong>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;configSections&gt;
      &lt;sectionGroup name="remoteServiceApi"&gt;
          &lt;section name="site" type="RemoteServiceApi.ApiSection" /&gt;
      &lt;/sectionGroup&gt;
  &lt;/configSections&gt;
  &lt;remoteServiceApi environment="Sandbox"&gt;
      &lt;site environment="Sandbox"
          APIKey="reallyLongHashKeyDev"
          APIUsername="samplejoe"
          APIPassword="joespass" /&gt;
      &lt;site environment="Production"
          APIKey="reallyLongHashKeyProd"
          APIUsername="samplejoe"
          APIPassword="joespass" /&gt;
  &lt;/remoteServiceApi&gt;
  </code></pre>
  
  <p><strong>Class File</strong>:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports System.Configuration
  
  Namespace RemoteServiceApi
      Public Class ApiSection
          Inherits ConfigurationSection
  
          &lt;ConfigurationProperty("site", IsRequired:=True)&gt; _
          Public Property site() As SiteElement
              Get
                  Return CType(Me("site"), SiteElement)
              End Get
              Set(value As SiteElement)
                  Me("site") = value
              End Set
          End Property
      End Class
  
      Public Class SiteElement
          Inherits ConfigurationElement
  
          &lt;ConfigurationProperty("Environment", DefaultValue:="Sandbox", IsRequired:=True)&gt; _
          Public Property Environment() As String
              Get
                  Return CStr(Me("Environment"))
              End Get
              Set(value As String)
                  Me("Environment") = value
              End Set
          End Property
  
          &lt;ConfigurationProperty("APIKey", IsRequired:=True)&gt; _
          Public ReadOnly Property APIKey() As String
              Get
                  Return CStr(Me("APIKey"))
              End Get
          End Property
  
          &lt;ConfigurationProperty("APIUsername", IsRequired:=True)&gt; _
          Public ReadOnly Property APIUsername() As String
              Get
                  Return CStr(Me("APIUsername"))
              End Get
          End Property
  
          &lt;ConfigurationProperty("APIPassword", IsRequired:=True)&gt; _
          Public ReadOnly Property APIPassword() As String
              Get
                  Return CStr(Me("APIPassword"))
              End Get
          End Property
      End Class
  
      Public Enum Environment
          Production
          Sandbox
      End Enum
  End Namespace
  </code></pre>
  
  <p>References I'm using as a guide:</p>
  
  <ul>
  <li><a href="http://msdn.microsoft.com/en-us/library/vstudio/2tw134k3%28v=vs.100%29.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-1" rel="nofollow">How to: Create Custom Configuration Sections Using ConfigurationSection</a></li>
  <li><a href="http://www.codeproject.com/Articles/8168/Creating-Custom-Configurations" rel="nofollow">Creating Custom Configurations</a> (published in 2004, so following cautiously)</li>
  </ul>