Hi,
I am getting the above error when I specify the sort attribute on a set in one of my entities. It seems to be related to the rehydration of the entity from the cache because the sort seems to be working on the initial load of the collection.
The stack trace for the exception is as follows:
Code:
Failed to compare two elements in the array.
at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer) at System.Collections.SortedList.IndexOfKey(Object key) at System.Collections.SortedList.get_Item(Object key) at Iesi.Collections.DictionarySet.Add(Object o) at NHibernate.Collection.Set.InitializeFromCache(ICollectionPersister persister, Object disassembled, Object owner) at NHibernate.Impl.SessionImpl.InitializeCollectionFromCache(Object id, Object owner, ICollectionPersister persister, PersistentCollection collection) at NHibernate.Impl.SessionImpl.InitializeCollection(PersistentCollection collection, Boolean writing) at NHibernate.Collection.PersistentCollection.ForceInitialization() at NHibernate.Impl.SessionImpl.InitializeNonLazyCollections() at NHibernate.Impl.SessionImpl.AssembleCacheEntry(CacheEntry entry, Object id, IClassPersister persister, Object optionalObject) at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id) at NHibernate.Type.ManyToOneType.ResolveIdentifier(Object id, ISessionImplementor session) at NHibernate.Type.ManyToOneType.Assemble(Object oid, ISessionImplementor session, Object owner) at NHibernate.Impl.CacheEntry.Assemble(Object[] values, Object result, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.CacheEntry.Assemble(Object instance, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.SessionImpl.AssembleCacheEntry(CacheEntry entry, Object id, IClassPersister persister, Object optionalObject) at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id) at NHibernate.Type.ManyToOneType.ResolveIdentifier(Object id, ISessionImplementor session) at NHibernate.Type.ManyToOneType.Assemble(Object oid, ISessionImplementor session, Object owner) at NHibernate.Impl.CacheEntry.Assemble(Object[] values, Object result, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.CacheEntry.Assemble(Object instance, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.SessionImpl.AssembleCacheEntry(CacheEntry entry, Object id, IClassPersister persister, Object optionalObject) at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id) at NHibernate.Type.ManyToOneType.ResolveIdentifier(Object id, ISessionImplementor session) at NHibernate.Type.ManyToOneType.Assemble(Object oid, ISessionImplementor session, Object owner) at NHibernate.Impl.CacheEntry.Assemble(Object[] values, Object result, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.CacheEntry.Assemble(Object instance, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.SessionImpl.AssembleCacheEntry(CacheEntry entry, Object id, IClassPersister persister, Object optionalObject) at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) at NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id) at NHibernate.Type.ManyToOneType.ResolveIdentifier(Object id, ISessionImplementor session) at NHibernate.Type.ManyToOneType.Assemble(Object oid, ISessionImplementor session, Object owner) at NHibernate.Impl.CacheEntry.Assemble(Object[] values, Object result, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.CacheEntry.Assemble(Object instance, Object id, IClassPersister persister, IInterceptor interceptor, ISessionImplementor session) at NHibernate.Impl.SessionImpl.AssembleCacheEntry(CacheEntry entry, Object id, IClassPersister persister, Object optionalObject) at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted) at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) at NHibernate.Impl.SessionImpl.Get(Type clazz, Object id) at NHibernate.Helper.Database.Get(Type type, Object id)
Object reference not set to an instance of an object.
at MyDomain.Entity.EntityComparer.Compare(Object x, Object y) at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)
When I debug this, the 2 objects that are being compared in my IComparer seem to be in a strange state, i.e. the private variables contain valid values but trying to access the public properties generates an ArgumentNullException in the debugger.
I have enabled caching on the parent, the child and the collection on the parent and when I disable the caching on the child, I no longer seem to get this error.
I am wondering if this is a bug in there somewhere or if it is something that I am doing incorrectly?
Thanks,
Jason