title: Cannot serialize member.... because it is an interface
body: <p>I have been having this problem and been pulling my hair out over it.  I have the followin error:</p>
  
  <blockquote>
    <p>Exception Details: System.NotSupportedException: Cannot serialize member HannaPrintsDataAccess.Customer.CustomerAddresses of type System.Collections.Generic.IList`1[[HannaPrintsDataAccess.CustomerAddress, HannaPrintsDataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.</p>
    
    <p>Source Error: </p>
    
    <p>Line 196:        Customer customer = OperationsManager.Instance.CustomerService.GetCustomer(7);
    Line 197:
    Line 198:        string xml = OperationsManager.Instance.CustomerService.GetCustomerAddressesXml(CustomerAddress.FindAll());
    Line 199:
    Line 200:        Order order = OperationsManager.Instance.OrderService.CreateOrderFromCart(xml);</p>
    
    <p>Source File: c:\HostingSpaces\greetwus\galadavetiye.com\wwwroot\HannaPrints\HannaPrints\WebUI\CreateGreetingCard.aspx.cs    Line: 198 </p>
    
    <p>Stack Trace: </p>
    
    <p>[NotSupportedException: Cannot serialize member HannaPrintsDataAccess.Customer.CustomerAddresses of type System.Collections.Generic.IList`1[[HannaPrintsDataAccess.CustomerAddress, HannaPrintsDataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] because it is an interface.]</p>
    
    <p>[InvalidOperationException: Cannot serialize member 'HannaPrintsDataAccess.Customer.CustomerAddresses' of type 'System.Collections.Generic.IList`1[[HannaPrintsDataAccess.CustomerAddress, HannaPrintsDataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]', see inner exception for more details.]
       System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc typeDesc, MemberInfo member, Type type) +889917
       System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo) +132........</p>
  </blockquote>
  
  <p>I have changed all my IList's to List's to see if that would do anything, but it didnt, infact, it didnt even take a second to load after making those changes, im guessing because the error happens even before it gets to that part.  I checked my remote files to see if it was uploading correctly and it was.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic; 
  using Castle.ActiveRecord;
  namespace HannaPrintsDataAccess { 
      public partial class Customer { 
          private IList _customerAddresses;
  
  
          public CustomerAddress GetPrimaryCustomerAddress()
          {
              foreach (CustomerAddress address in _customerAddresses)
              {
                  if (address.IsPrimary)
                      return address;
              }
              return null;
          }
  
  
          [HasMany(typeof(CustomerAddress), ColumnKey = "CustomerId", Table = "Customer")]
          public virtual IList&lt;CustomerAddress&gt; CustomerAddresses
          {
              get
              {
                  return this._customerAddresses;
              }
              set
              {
                  this._customerAddresses = value;
              }
          }
      }
  }
  </code></pre>
  
  <p>The error happens when this code is activated:</p>
  
  <pre><code>protected void orderButton_Click(object sender, EventArgs e)
  {
      Customer customer = OperationsManager.Instance.CustomerService.GetCustomer(7);
  
      string xml = OperationsManager.Instance.CustomerService.GetCustomerAddressesXml(CustomerAddress.FindAll());
  
      Order order = OperationsManager.Instance.OrderService.CreateOrderFromCart(xml);
      OperationsManager.Instance.CartService.MoveCart("MyDesigns");
  
      Response.Redirect("~/Customer/PayByCreditCard.aspx?orderGuid=" + order.OrderGuid);
  }
  </code></pre>
  
  <p>The CustomerAddress class:</p>
  
  <pre><code>using System.IO;
  using System.Xml.Serialization;
  using Castle.ActiveRecord;
  
  
  namespace HannaPrintsDataAccess
  {
  public partial class CustomerAddress
  {
      public string ToXml()
      {
          XmlSerializer serializer = new XmlSerializer(GetType());
          MemoryStream memoryStream = new MemoryStream();
          serializer.Serialize(memoryStream, this);
          memoryStream.Seek(0, SeekOrigin.Begin);
          return new StreamReader(memoryStream).ReadToEnd();
      }
  
      [BelongsTo("CustomerId")]
      public virtual Customer Customer { get; set; }
  }
  }
  </code></pre>