Handling “Unable to load type [your-model] required for deserialization” when using Redis to store custom objects in User sessions with Azure.

In our latest project I have been storing an instance of an object in the User's session, which can be recycled on each page load and cuts down load times but 60%. This simple model, which of course must be decorated with [Serializable] or you'll get the error “Type 'xxx' in Assembly 'xxx, Version=...' is not marked as serializable”, has a bunch of reference data pertaining to the User's location. So, when I added some additional data which changed the class, Redis didn't like that. Not. One. Bit.



The full error would be something like

Unable to load type Sitecore.Feature… required for deserialization.
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.Serialization.SerializationException: 
Unable to load type Sitecore.Feature… required for deserialization.

So what we have here is objects still stored in a session that aren't lining up with the model. It's time to get into Azure and kick those suckers out! Before doing so, I should say we don't store anything critical in a User's session so the result of this is just another lookup and new object stored. If you're relying on these sessions, you'd want to schedule this command, but in this case you'd be deploying smarter anyways.

Once in Azure, open your Redis Cache instance and click the "Console" option in the top of the page. 

From here, execute the following command which will purge all instances of the old object, and rectify the error.

flushall 

Get it? That's why the banner's a drain. Comedy gold.

P.S. This is also part of the Sitecore upgrade steps, so if you've done one of those, you know about this and shame on you for not figuring it out on your own.