title: Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag'
body: <pre><code>public List&lt;Application&gt; FindAll()
  {
      using (ISession NSession = SessionProvider.GetSession())
      {
          ICriteria CriteriaQuery =
              NSession.CreateCriteria(typeof(Application));
  
          return (List&lt;Application&gt;) CriteriaQuery.List&lt;Application&gt;();
  
      }
  }
  </code></pre>
  
  <p>I am getting an exception in which application class is the following:</p>
  
  <pre><code>public class Application
  {
       private string _name;
       private Developer _developer;
       private int _id;
       private List&lt;Bug&gt; _bugs;
  
      public Application()
      {
      }
  
      public virtual int ApplicationId
      {
          get { return _id; }
          set { _id = value; }
      }
  
      public virtual Developer Developer
      {
          get { return _developer; }
          set { _developer = value; }
      }
  
      public virtual string Name
      {
          get { return _name; }
          set { _name = value; }
      }
  
      public virtual List&lt;Bug&gt; Bugs
      {
          get { return _bugs; }
          set { _bugs = value; }
      }
  }
  </code></pre>
  
  <p>System.InvalidCastException: Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag<code>1[BugTracker.Model.Bug]' to type 'System.Collections.Generic.List</code>1[BugTracker.Model.Bug]'.</p>
  
  <p>Here is the application.hbm.xml:</p>
  
  <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="BugTracker.Model"
                     assembly="BugTracker"&gt;
    &lt;class name="Application" table="Applications" lazy="false"&gt;
      &lt;id name="ApplicationId" column ="ApplicationId" type="int" unsaved-value ="0"&gt;
        &lt;generator class ="native"&gt;&lt;/generator&gt;
      &lt;/id&gt;
  
      &lt;property name ="Name" column="Name"/&gt;
  
      &lt;component access ="field.camelcase-underscore" name ="Developer"
                 class="Developer"&gt;
        &lt;property access ="field.camelcase-underscore" 
                  column ="DeveloperFirstName" name="FirstName"/&gt;
        &lt;property access ="field.camelcase-underscore" 
                  column="DeveloperLastName" name="LastName"/&gt;
      &lt;/component&gt;
  
      &lt;bag cascade="all-delete-orphan"
            inverse ="true"
            name ="Bugs"
            lazy="false"
            access ="field.camelcase-underscore"&gt;
        &lt;key column ="ApplicationId"/&gt;
        &lt;one-to-many class ="Bug"/&gt;
      &lt;/bag&gt;
  
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>I'm newbie to Nhibernate and find it very complicated. I really cannot see the issue.
  The exception occurs at the last line of Application Class Constructor. </p>