I'm using two named caches in AppFabric:
I have a separate VS Project which is attempting to enumerate the entire contents of the cache and output each item:
foreach (string regionName in cache.GetSystemRegions()) {
foreach (var cacheItem in cache.GetObjectsInRegion(regionName)) {
Trace.WriteLine(String.Format("{0} \t\t {1}", cacheItem.Key, cacheItem.Value));
}
}
This works great for CacheA, but running that with CacheB throws an exception (when cache.GetObjectsInRegion() returns something non-null):
Assembly 'Microsoft.Web.DistributedCache, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not found. ---> System.Runtime.Serialization.SerializationException: Assembly 'Microsoft.Web.DistributedCache, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not found. at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID, Type declaredType, String name, String ns) at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, String name, String ns) at System.Runtime.Serialization.NetDataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader) at Microsoft.ApplicationServer.Caching.Utility.Deserialize(Byte[][] buffers, Boolean checkTypeToLoad, Object context, IEnumerable`1 knownTypes) at Microsoft.ApplicationServer.Caching.Utility.Deserialize(Byte[][] buffers, Boolean checkTypeToLoad, Object context) at Microsoft.ApplicationServer.Caching.Utility.Deserialize(Byte[][] buffers, Boolean checkTypeToLoad) at Microsoft.ApplicationServer.Caching.CacheEnumerator.MoveNext()
I saw unable to read azure cached data from a different application and added a reference to my other project which contains the class these objects were before serialization (I actually want to just view the values as they're serialized and stored in the cache), but that alone didn't change anything.
Session items are stored in AppFabric Cache using Microsoft.Web.DistributedCache.SerializableSessionStateStoreData
.
Here is the reflected code
[DataContract]
internal sealed class SerializableSessionStateStoreData
{
[DataMember(Name = "Keys")]
private string[] _keys;
[DataMember(Name = "Values")]
private object[] _values;
[DataMember(Name = "Timeout")]
private int _timeout;
[DataMember(Name = "SessionStateActions")]
private SessionStateActions _sessionStateActions;
public SerializableSessionStateStoreData(SessionStateStoreData storeData, SessionStateActions sessionStateActions)
{
...
}
public Tuple<SessionStateStoreData, SessionStateActions> Restore()
{
...
}
}
When you try to get a session item outside web context, AppFabric cache client is unable to deserialize the data item because it is serialized in an unknow type (defined in Microsoft.Web.DistributedCache.dll).
Add a reference to Microsoft.Web.DistributedCache.dll
This will also require System.Web.dll because it requires System.Web.SessionState.SessionStateStoreData