title: NHibernate 3.3 query caching throwing exception
body: <p>I recently upgraded our app to use NHibernate 3.3 and wanted to enable caching. </p>
  
  <p>We're in a multitenant enviroment, so I want each session factory to keep a region for each client. </p>
  
  <p>Here's my NHibernate config: </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="cache.use_query_cache"&gt;true&lt;/property&gt;
      &lt;property name="cache.use_second_level_cache"&gt;true&lt;/property&gt;
      &lt;property name="cache.provider_class"&gt;NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache&lt;/property&gt;
      &lt;property name="connection.connection_string"&gt;Data Source=localhost; database=test;user=test; password=test;&lt;/property&gt;
      &lt;property name="show_sql"&gt;false&lt;/property&gt;
      &lt;property name="command_timeout"&gt;1000&lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>and in our session factory generator...</p>
  
  <pre><code> private static ISessionFactory GetSessionFactory(string connectionString, string driverClass = NormDriverClass, string prefix = null)
      {
          Configuration configuration = new Configuration();
          configuration.Configure().SetProperty(ConnectionStringProperty, connectionString);
          configuration.Properties.Add(ConnectionDriverProperty, driverClass);
          configuration.Properties.Add("regionPrefix", prefix ?? "default");
          configuration.AddAssembly(typeof(Foo).Assembly);
  
          return configuration.BuildSessionFactory();
      }
  </code></pre>
  
  <p>I've set the query to cachable: </p>
  
  <pre><code>query.SetCacheable(true).SetCacheMode(CacheMode.Normal); 
  </code></pre>
  
  <p>I get the following error every time</p>
  
  <pre><code>System.IndexOutOfRangeException : Index was outside the bounds of the array.
  at NHibernate.Type.TypeHelper.Disassemble(Object[] row, ICacheAssembler[] types, Boolean[] nonCacheable, ISessionImplementor session, Object owner)
  at NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session)
  at NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result)
  at NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
  at NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results)
  at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results)
  at NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters)
  at NHibernate.Impl.SqlQueryImpl.List()
  </code></pre>
  
  <p>Thinking the cache provider was to blame, I switched back to </p>
  
  <pre><code>&lt;property name="cache.provider_class"&gt;NHibernate.Cache.HashtableCacheProvider,NHibernate&lt;/property&gt;
  </code></pre>
  
  <p>No change. </p>
  
  <p>I removed the region prefix code, no change. </p>
  
  <p>Setting "Use_query_cache" to false fixes the runtime exception but then no cache is used. </p>