title: XMLserializer, Entity Framework : Cannot serialize member of type ICollection see inner exception for more details
body: <p>I want to map XML elements into my database table (using Entity Framework):</p>
  
  <pre><code>var xmlSerializer = new XmlSerializer(typeof(Participant), new XmlRootAttribute("participant"));
  var participant = (Participant)xmlSerializer.Deserialize(new StringReader(content));
  </code></pre>
  
  <p>I have Participant table which I can access by </p>
  
  <pre><code>[XmlRoot("participant", Namespace = "")]
      public partial class Participant
      {
          [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",     "CA2214:DoNotCallOverridableMethodsInConstructors")]
          public Participant()
          {
              this.GroupParticipant = new HashSet&lt;GroupParticipant&gt;();
              this.ParticipantAddress = new HashSet&lt;ParticipantAddress&gt;();
              this.ParticipantPublisher = new HashSet&lt;ParticipantPublisher&gt;();
              this.ParticipantJob = new HashSet&lt;ParticipantJob&gt;();
              this.ParticipantProvider = new HashSet&lt;ParticipantProvider&gt;();
          }
          [XmlElement("firstName")]
          public string FirstName { get; set; }
  
          [XmlElement("lastName")]
          public string LastName { get; set; }
  
          [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
          //[XmlElement("address")]
          //[XmlElement("address")]
          //[XmlArray("HashSet&lt;ParticipantAddress&gt;"), XmlElement("address")]
          //[XmlArrayItem("ICollection&lt;ParticipantAddress&gt;")]
          //[XmlAttribute(DataType = "ICollection&lt;ParticipantAddress&gt;",  AttributeName = "address")]
  
  [XmlElement("address", typeof(List&lt;ParticipantAddress&gt;))]
          public virtual ICollection&lt;ParticipantAddress&gt; ParticipantAddress { get; set; }
  }
  </code></pre>
  
  <p>ParticipantAddress is ICollection:</p>
  
  <pre><code>[Serializable]
      [XmlInclude(typeof(HashSet&lt;ParticipantAddress&gt;))]
      public partial class ParticipantAddress
      {
          public int ParticipantAddressId { get; set; }
          public int ParticipantId { get; set; }
  
          [XmlElement("city")]
          public string City { get; set; }
  
          [XmlElement("state")]
          public string State { get; set; }
  
          [XmlElement("zipCode")]
          public string ZipCode { get; set; }
  
          public virtual Participant Participant { get; set; }
      }
  </code></pre>
  
  <p>Exception says:</p>
  
  <blockquote>
    <p>{"There was an error reflecting type 'x.Participant'."}</p>
  </blockquote>
  
  <p>My inner Exception says:</p>
  
  <blockquote>
    <p>{"Cannot serialize member 'xParticipant.ParticipantAddress' of type 'System.Collections.Generic.ICollection`1[[x.ParticipantAddress, APS.Data.BatchInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]', see inner exception for more details."}</p>
  </blockquote>
  
  <p>I am reading XML by streamReader.</p>
  
  <p>I have tried </p>
  
  <ul>
  <li>[XMLArray]</li>
  <li>Changing ICollection to List </li>
  <li>make class serializable</li>
  </ul>
  
  <p>Is there any other way to overcome this problem or any examples related to my question or any changes I need to implement in my code?</p>