0

Issue :- When using redis cache with interface classes for glass mapper is throwing below issue

Sitecore version : 9.0.2 glassmapper : Version=4.4.0.199

Type 'Glass.Mapper.Sc.LazyItemEnumerable`1[[XXX.Entities.ICommunitiesBuilding, XXX.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' in Assembly 'Glass.Mapper.Sc, Version=4.4.0.199, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Query:- ICommunitiesBuilding is an interface class inheriting multiple interfaces

 public interface ICommunitiesBuilding : IPaymentCommunityWise, IBaseModel
    {
        [SitecoreField("Name")]
        string Name { get; set; }

        [SitecoreField("IsVilla")]
        bool IsVilla { get; set; }

        [SitecoreField("IsEmpower")]
        bool IsEmpower { get; set; }

        [SitecoreField("PropertyCode")]
        string PropertyCode { get; set; }

        [SitecoreChildren]
        IEnumerable<ICommunitiesBuilding> Children { get; set; }
    }

I think the children field which is child of same interface & IEnumerable which is throwing the issue during Redis cache read. I tried changing IEnumerable to LIST but no luck as it requires iteration. any thoughts to resolve this issue

Appreciate any help.

Full error log

System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +14121154
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +88
   System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +234
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +194
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +272
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +590
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArrayMember(WriteObjectInfo objectInfo, NameInfo arrayElemTypeNameInfo, Object data) +619
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo) +1484
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +292
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +576
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +214
   Sitecore.SessionProvider.Redis.RedisUtility.GetBytesFromObject(Object data, Boolean compress) +316
   Sitecore.SessionProvider.Redis.RedisUtility.AppendUpdatedOrNewItemsInList(ChangeTrackingSessionStateItemCollection sessionItems, List`1 list, Boolean compress) +201
   Sitecore.SessionProvider.Redis.RedisConnectionWrapper.TryUpdateIfLockIdMatchPrepare(String sessionId, Object lockId, ISessionStateItemCollection data, Int32 sessionTimeout, String[]& keyArgs, Object[]& valueArgs) +289
   Sitecore.SessionProvider.Redis.RedisConnectionWrapper.TryUpdateAndReleaseLockIfLockIdMatch(String sessionId, Object lockId, ISessionStateItemCollection data, Int32 sessionTimeout) +59
   Sitecore.SessionProvider.Redis.RedisSessionStateProvider.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +917
   System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +859
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +223
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +220
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +94
1
  • I used to do something similar except that I stored it into memory, so I didn't run into this issue. However I was running into issues when the code couldn't load the content inside the LazyItemEnumerable anymore if it hadn't done so in the initial request. I changed my approach to just storing a much simpler object in cache which had expanded the entire object graph.
    – Jeroen
    Sep 2 '21 at 21:28

Browse other questions tagged or ask your own question.