NHibernate 3.3 and SysCache

nhibernatesyscache

The current version of SysCache does not appear to work with NHibernate 3.3. I replaced the NHibernate dlls in my web/bin directory and left the SysCache dll (which works with 3.2) untouched. Now when IIS tries to do a pre-bind it loads the SysCache dll and tries to bind it to NHibernate 3.2.0.4000 and fails.

[FileLoadException: Could not load file or assembly 'NHibernate,
Version=3.2.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'
or one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)] System.RuntimeTypeHandle.GetTypeByName(String name,
Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName,
ObjectHandleOnStack type) +0
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean
throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) +95
System.RuntimeType.GetType(String typeName, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
+54 System.Type.GetType(String typeName) +50 NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName
name, Boolean throwOnError) +338
NHibernate.Cfg.SettingsFactory.CreateCacheProvider(IDictionary`2
properties) +175

[HibernateException: could not instantiate CacheProvider:
NHibernate.Caches.SysCache.SysCacheProvider,
NHibernate.Caches.SysCache]
NHibernate.Cfg.SettingsFactory.CreateCacheProvider(IDictionary2
properties) +256
NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary
2 properties)
+3449 NHibernate.Cfg.Configuration.BuildSettings() +29 NHibernate.Cfg.Configuration.BuildSessionFactory() +44

If I comment out the configuration in the web.config all is well:

<property name="cache.use_second_level_cache">true</property>
<property name="cache.use_query_cache" >true</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>

The download site for NHibernate caches at NHibernate Contrib does not have a download for the latest version.

Best Answer

A different and slightly simpler approach is to override the reference to the 3.2 version of NHibernate in your web.config or app.config with a reference to the desired version 3.3 like so:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="NHibernate" culture="neutral" publicKeyToken="aa95f207798dfdb4" />
      <bindingRedirect newVersion="3.3.0.4000" oldVersion="0.0.0.0-3.3.0.4000" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

I've just tried this myself and it works as expected.

Related Topic