title: Error building SessionFactory in nHibernate
body: <p>I am getting an "ArgumentOutOfRangeException" on parameter index whenever I try to instantiate a session factory in nHibernate. The error comes from a procedure deep in the bowels of nHibernate. I can post the stack-trace of the error if that would help.</p>
  
  <p>This is on a fresh project with a pretty simple three tier architecture. The data layer maps the nHibernate classes to simple interfaces which are implemented by the business layer. Currently there is only one interface set and mapping file being used by nHibernate. Hopefully my issue is easy to spot.</p>
  
  <p>Here is the function where I build the sessionFactory.</p>
  
  <pre><code>  Private Shared Function SessionFactory() As ISessionFactory
          If _sessionFactory Is Nothing Then
              Dim config As New NHibernate.Cfg.Configuration
              config.Configure()
              config.AddClass(GetType(ICompanyProperty))
              _sessionFactory = config.BuildSessionFactory            
          End If
          Return _sessionFactory
      End Function
  </code></pre>
  
  <p>Here is my hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
    &lt;session-factory&gt;
      &lt;property name="connection.provider"&gt;
        NHibernate.Connection.DriverConnectionProvider     
      &lt;/property&gt;
      &lt;property name="dialect"&gt;
        NHibernate.Dialect.MsSql2005Dialect
      &lt;/property&gt;
      &lt;property name="connection.driver_class"&gt;
        NHibernate.Driver.SqlClientDriver
      &lt;/property&gt;
      &lt;property name="connection.connection_string"&gt;
        Data Source=dataserver.domain.ad;Initial Catalog=LABs;Integrated Security=SSPI
      &lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>And the mapping file of the interface I am mapping.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Sample.Data" namespace="Sample.Data"&gt;
    &lt;class name="ICompanyProperty" table="CompanyProperty"&gt;
      &lt;id name="CompanyPropertyID" column="CompanyPropertyID"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;    
      &lt;discriminator column="PropertyType" type="String" /&gt;
      &lt;property name="CompanyID" /&gt;
      &lt;property name="PropertyName" /&gt;    
      &lt;subclass discriminator-value="SQL" name="ISQLLookupCompanyProperty"&gt;
        &lt;property name="TableName" /&gt;      
        &lt;property name="KeyField" /&gt;
        &lt;property name="ValueField" /&gt;
        &lt;property name="ConnectionString" /&gt;
      &lt;/subclass&gt;
      &lt;subclass discriminator-value="LIST" name="ILookupCompanyProperty" /&gt;    
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>And the interfaces</p>
  
  <pre><code>Public Interface ICompanyProperty
      Property CompanyPropertyID() As Integer
      Property PropertyName() As String
      Property CompanyID() As Integer
      Property PropertyType() As String
  End Interface
  
  Public Interface ILookupCompanyProperty
      Inherits ICompanyProperty
  End Interface
  
  Public Interface ISQLLookupCompanyProperty
      Inherits ILookupCompanyProperty
  
      Property TableName() As String
      Property KeyField() As String
      Property ValueField() As String
      Property ConnectionString() As String
  End Interface
  </code></pre>
  
  <p>Thank you!</p>
  
  <p>Edit: The stacktrace was requested. here it is from my call of build session factory to the error.</p>
  
  <pre><code>at System.Collections.ArrayList.get_Item(Int32 index)
  at NHibernate.SqlCommand.InFragment.ToFragmentString()
  at NHibernate.Persister.Entity.SingleTableEntityPersister.DiscriminatorFilterFragment(String alias)
  at NHibernate.Persister.Entity.SingleTableEntityPersister.FilterFragment(String alias)
  at NHibernate.Persister.Entity.AbstractEntityPersister.FilterFragment(String alias, IDictionary`2 enabledFilters)
  at NHibernate.Loader.Entity.EntityJoinWalker..ctor(IOuterJoinLoadable persister, String[] uniqueKey, Int32 batchSize, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters)
  at NHibernate.Loader.Entity.EntityLoader..ctor(IOuterJoinLoadable persister, String[] uniqueKey, IType uniqueKeyType, Int32 batchSize, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters)
  at NHibernate.Loader.Entity.EntityLoader..ctor(IOuterJoinLoadable persister, Int32 batchSize, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters)
  at NHibernate.Loader.Entity.EntityLoader..ctor(IOuterJoinLoadable persister, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters)
  at NHibernate.Loader.Entity.BatchingEntityLoader.CreateBatchingEntityLoader(IOuterJoinLoadable persister, Int32 maxBatchSize, LockMode lockMode, ISessionFactoryImplementor factory, IDictionary`2 enabledFilters)
  at NHibernate.Persister.Entity.AbstractEntityPersister.CreateEntityLoader(LockMode lockMode, IDictionary`2 enabledFilters)
  at NHibernate.Persister.Entity.AbstractEntityPersister.CreateEntityLoader(LockMode lockMode)
  at NHibernate.Persister.Entity.AbstractEntityPersister.CreateLoaders()
  at NHibernate.Persister.Entity.AbstractEntityPersister.PostInstantiate()
  at NHibernate.Persister.Entity.SingleTableEntityPersister.PostInstantiate()
  at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
  at NHibernate.Cfg.Configuration.BuildSessionFactory()
  </code></pre>
  
  <p>Edit2: When I remove the discriminator I no longer get this error. Am I not doing that right?</p>
  
  <p>Edit 3: When I download the source code for nHibernate, build it on my own, link to it's debug output and run it, I get a completely different error about ProxyFactoryFactory not being configured.</p>