NHibernate.Caches.Redis icon indicating copy to clipboard operation
NHibernate.Caches.Redis copied to clipboard

System.Object' to type 'System.Byte[]

Open craigvn opened this issue 8 years ago • 8 comments

I added this nuget 3.0 beta 4 to an app and I get the error System.Object' to type 'System.Byte[]. Any ideas?

craigvn avatar May 14 '16 22:05 craigvn

Hi @craigvn,

What's the full stack trace? Also, how are you configuring the cache provider?

TheCloudlessSky avatar May 15 '16 02:05 TheCloudlessSky

Configuration is

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

Stack trace is

System.InvalidCastException: Unable to cast object of type 'System.Object' to type 'System.Byte[]'. at NHibernate.Type.BinaryType.ToInternalFormat(Object bytes) at NHibernate.Type.AbstractBinaryType.DeepCopyNotNull(Object value) at NHibernate.Type.MutableType.DeepCopy(Object value, EntityMode entityMode, ISessionFactoryImplementor factory) at NHibernate.Type.AbstractType.Assemble(Object cached, ISessionImplementor session, Object owner) at NHibernate.Type.TypeHelper.Assemble(Object[] row, ICacheAssembler[] types, ISessionImplementor session, Object owner) at NHibernate.Cache.Entry.CacheEntry.Assemble(Object[] values, Object result, Object id, IEntityPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Cache.Entry.CacheEntry.Assemble(Object instance, Object id, IEntityPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Event.Default.DefaultLoadEventListener.AssembleCacheEntry(CacheEntry entry, Object id, IEntityPersister persister, LoadEvent event) at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromSecondLevelCache(LoadEvent event, IEntityPersister persister, LoadType options) at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) at NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) at NHibernate.Impl.SessionImpl.Get(String entityName, Object id) at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id) at NHibernate.Impl.SessionImpl.Get[T](Object id)

craigvn avatar May 15 '16 02:05 craigvn

According to your configuration, you're using NHibernate.Caches.SysCache.SysCacheProvider and not this library (NHibernate.Caches.Redis). You'll have to report this to the official NHibernate project.

TheCloudlessSky avatar May 15 '16 12:05 TheCloudlessSky

Ah, I stuffed up. My config is actually

NHibernate.Caches.Redis.RedisCacheProvider, NHibernate.Caches.Redis

Can this be related to lazy load properties?

craigvn avatar May 15 '16 21:05 craigvn

Ok.

  1. It shouldn't be related to lazy-loaded properties. I've used them in the past without any issues. If you remove the lazy-loaded properties, do you get caching exceptions?
  2. What's all the configuration for RedisCacheProvider (including SetConnectionMultiplexer and SetOptions)?
  3. What's the mapping cache configuration for each of your entities?
  4. Can you make a small reproducible failure case (e.g. a project you can send me)?

TheCloudlessSky avatar May 16 '16 12:05 TheCloudlessSky

Thanks.

I will try and make a test case and get back to you once I find the exact area causing the problem.

Craig

On Mon, May 16, 2016 at 10:13 PM, Adrian Phinney [email protected] wrote:

Ok.

  1. It shouldn't be related to lazy-loaded properties. I've used them in the past without any issues. If you remove the lazy-loaded properties, do you get caching exceptions?
  2. What's all the configuration for RedisCacheProvider (including SetConnectionMultiplexer and SetOptions)?
  3. What's the mapping cache configuration for each of your entities?
  4. Can you make a small reproducible failure case (e.g. a project you can send me)?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/TheCloudlessSky/NHibernate.Caches.Redis/issues/17#issuecomment-219410996

craigvn avatar May 16 '16 19:05 craigvn

The query cache seems to be working no problems, I have just pushed it to production :-)

The second-level cache still gives intermittent problems which I am looking into. It seems if an entity is loaded twice in a session, or something like that, it can give an error depending on the mapping. I need to investigate more.

craigvn avatar May 18 '16 00:05 craigvn

Ok, I'm interested in seeing what you can come up with to reproduce this problem.

TheCloudlessSky avatar May 18 '16 15:05 TheCloudlessSky