title: WCF: Serializing and Deserializing generic collections
body: <p>I have a class Team that holds a generic list:</p>
  
  <pre><code>[DataContract(Name = "TeamDTO", IsReference = true)]
  public class Team
  {
      [DataMember]
      private IList&lt;Person&gt; members = new List&lt;Person&gt;();
  
      public Team()
      {
          Init();
      }
  
      private void Init()
      {
          members = new List&lt;Person&gt;();
      }
  
      [System.Runtime.Serialization.OnDeserializing]
      protected void OnDeserializing(StreamingContext ctx)
      {
          Log("OnDeserializing of Team called");
          Init();
          if (members != null) Log(members.ToString());
      }
  
      [System.Runtime.Serialization.OnSerializing]
      private void OnSerializing(StreamingContext ctx)
      {
          Log("OnSerializing of Team called");
          if (members != null) Log(members.ToString());
      }
  
      [System.Runtime.Serialization.OnDeserialized]
      protected void OnDeserialized(StreamingContext ctx)
      {
          Log("OnDeserialized of Team called");
          if (members != null) Log(members.ToString());
      }
  
      [System.Runtime.Serialization.OnSerialized]
      private void OnSerialized(StreamingContext ctx)
      {
          Log("OnSerialized of Team called");
          Log(members.ToString());
      }
  </code></pre>
  
  <p>When I use this class in a WCF service, I get following log output</p>
  
  <pre><code>OnSerializing of Team called    
  System.Collections.Generic.List 1[XXX.Person]
  
  OnSerialized of Team called    
  System.Collections.Generic.List 1[XXX.Person]
  
  OnDeserializing of Team called    
  System.Collections.Generic.List 1[XXX.Person]
  
  OnDeserialized of Team called    
  XXX.Person[]
  </code></pre>
  
  <p>After the deserialization <code>members</code> is an Array and no longer a generic list although the field type is IList&lt;> (?!)
  When I try to send this object back over the WCF service I get the log output</p>
  
  <pre><code>OnSerializing of Team called
  XXX.Person[]
  </code></pre>
  
  <p>After this my unit test crashes with a System.ExecutionEngineException, which means the WCF service is not able to serialize the array. (maybe because it expected a IList&lt;>)</p>
  
  <p>So, my question is: Does anybody know why the type of my IList&lt;> is an array after deserializing and why I can't serialize my Team object any longer after that?</p>
  
  <p>Thanks</p>