NHibernate 3.3 and SysCache

7.8k views Asked by At

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.

2

There are 2 answers

1
Baz1nga On BEST ANSWER

The issue probably is that the SysCache Dll is built using NHibernate 3.2.0 and it is not compatible with NHibernate 3.3.0. An easy way around this is to checkout the trunk of the nhibernate config project or the Cache solution only from https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Caches update the NHibernate reference to use the version that you are using and then rebuild and use the latest cache dlls. Since its a minor upgrade there shouldnt be any code changes required and you should be safe.

Try it and let me know how it goes.

0
Oliver On

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.