Blog/Sitecore ·27 Apr 2019 ·
Don't forget to clear your session storage during Sitecore upgrade
A short story how to fix ERROR ProcessExpiredItems => System.Runtime.Serialization.SerializationException: Cannot get the member '<.ctor>b__2'. exception.
Recently I have been helping with the migration of one project to Azure. At the same time, the project has been upgraded to Sitecore 8.2 Update-1 and then again 8.2 Update-7. Before we deployed our site to Azure, the clean version of Sitecore 8.2 Update-1 was installed there.
The exception: SerializationException on ProcessExpiredItems
After deployment to staging and production, we noticed the huge number of exceptions like this:
ERROR ProcessExpiredItems => System.Runtime.Serialization.SerializationException: Cannot get the member 'b__2'.
at System.Reflection.MemberInfoSerializationHolder.GetRealObject(StreamingContext context)
at System.Runtime.Serialization.ObjectManager.ResolveObjectReference(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at Sitecore.SessionProvider.Redis.RedisUtility.GetObjectFromBytes(Byte[] dataAsBytes)
at Sitecore.SessionProvider.Redis.StackExchangeClientConnection.GetSessionDataStatic(Object rowDataFromRedis)
at Sitecore.SessionProvider.Redis.RedisConnectionWrapper.TakeWriteLockAndGetExpiredData(String sessionId, DateTime signalTime, DateTime lockTime, Int32 expirationTimeout, ISessionStateItemCollection& data, Int32& sessionTimeout)
at Sitecore.SessionProvider.Redis.RedisSessionStateProvider.OnProcessExpiredItems(DateTime signalTime)
Tracking down which type failed to deserialize
It took me a full day of work to figure out what class exactly is to be deserialized. I had to implement a custom Redis provider and a lot of C# Reflection, but at the end of the day I saw this:

The cause: sessions written by the older Sitecore version
I reached out to Sitecore support and they quickly provided me a solution. The reason for the exceptions was ‘old’ sessions created by the earlier version of Sitecore (8.2 u1) that cannot be processed by the new version (8.2 u7). The solution for this is to just clear the session storage. It is mentioned in the Sitecore upgrade guide in the topic ‘1.4.7 Upgrade the Session Database’.
How to clear Redis session storage on Azure
Alex from Sitecore support gave me the following steps to clear Redis session storage on Azure:
- Stop all Sitecore XP instances that use the same session database
- Clear the Redis: this can be done by using Redis Cache console - Please note that the unprocessed data (sessions added by Sitecore 8.2 u7) will be cleaned from the Redis Cache
- In Azure, go to the Redis Cache and click the “Console” option.
- Execute the flushall command to clean up all records from the session store; https://stackoverflow.com/questions/37227696/clear-azure-redis-cache
- Start all XP instances.
Here is a CustomRedisProvider.cs that I used for debugging.