title: Unable to cast object of type 'System.Collections.ArrayList' to type 'System.Collections.Generic.IEnumerable'
body: <p>I recently upgraded Windows SmartClient solution from nHibernate 2.2 to 4.0 and am getting an exception when writing to the db. </p>
  
  <p>The exception is thrown at this code:</p>
  
  <pre><code>this.session.Save(this.Location); // NHibernate.ISession
  tx.Commit(); // exception thrown here
  </code></pre>
  
  <p>The exception is:</p>
  
  <blockquote>
    <p>'System.InvalidCastException' in NHibernate.dll
    System.InvalidCastException: 
    Unable to cast object of type 'System.Collections.ArrayList' 
    to type 'System.Collections.Generic.IEnumerable`1[System.Object]'.</p>
  </blockquote>
  
  <p>There are several lists in the object being saved, here is a couple representative ones:</p>
  
  <pre><code>protected System.Collections.IList locationList;
  public virtual System.Collections.IList AssociatedLocationList
  {
      get
      {
          if (this.locationList == null)
          {
              this.locationList = new System.Collections.ArrayList();
          }
          return this.locationList;
      }
      set { this.locationList = value; }
  }
  protected System.Collections.Generic.IList&lt;Inspection&gt; inspectionList;
  public virtual System.Collections.Generic.IList&lt;Inspection&gt; InspectionList
  {
      get
      {
          if (this.inspectionList == null)
          {
              this.inspectionList = new System.Collections.Generic.List&lt;Inspection&gt;();
          }
  
          return this.inspectionList;
      }
      set { this.inspectionList = value; }
  }
  </code></pre>
  
  <p>Note that some have a type specified and some don't.</p>
  
  <p>One suggestion <a href="https://stackoverflow.com/questions/6808978/unable-to-cast-object-of-type-nhibernate-collection-generic-persistentgenericba">here</a> is set the property to an <code>IList</code>, but I already have it as that.</p>
  
  <p>What can be done?</p>