读取AppFabric内容引发Assembly异常
本文关键字:Assembly 异常 AppFabric 读取 | 更新日期: 2023-09-27 18:19:06
我在AppFabric中使用两个命名缓存:
- 缓存只是对[string,string],并没有以任何特殊的方式使用
- CacheB是一对[string,object](其中object是可序列化的类型),并用作ASP的会话存储。NET MVC4站点
我有一个单独的VS项目,它试图枚举缓存的整个内容并输出每个项目:
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));
}
}
这对于CacheA非常有效,但是与CacheB一起运行会抛出异常(当cache.GetObjectsInRegion()返回非空值时):
<>之前Microsoft.Web大会"。未找到DistributedCache, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'。--> System.Runtime.Serialization.SerializationException: Assembly 'Microsoft.Web。未找到DistributedCache, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'。在System.Runtime.Serialization.XmlObjectSerializerReadContextComplex。InternalDeserializeInSharedTypeMode(XmlReaderDelegator xmlReader, Int32 declaredTypeID,类型declaredType,字符串名称,字符串ns)在System.Runtime.Serialization.XmlObjectSerializerReadContextComplex。InternalDeserialize(XmlReaderDelegator xmlReader,类型声明类型,字符串名称,字符串ns)在System.Runtime.Serialization.NetDataContractSerializer。InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName)在System.Runtime.Serialization.XmlObjectSerializer。InternalReadObject(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver)在System.Runtime.Serialization.XmlObjectSerializer。ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver DataContractResolver)在System.Runtime.Serialization.XmlObjectSerializer。ReadObject (XmlDictionaryReader读者)在Microsoft.ApplicationServer.Caching.Utility。反序列化(Byte[][] buffers, Boolean checkTypeToLoad, Object context, IEnumerable ' 1 knownTypes)在Microsoft.ApplicationServer.Caching.Utility。反序列化(Byte[][] buffers, Boolean checkTypeToLoad, Object context)在Microsoft.ApplicationServer.Caching.Utility。反序列化(Byte[][] buffers, Boolean checkTypeToLoad)在Microsoft.ApplicationServer.Caching.CacheEnumerator.MoveNext ()之前我看到无法从不同的应用程序读取azure缓存数据,并添加了一个引用到我的其他项目,其中包含这些对象在序列化之前的类(我实际上只是想查看它们被序列化和存储在缓存中的值),但这本身并没有改变任何东西
会话项使用Microsoft.Web.DistributedCache.SerializableSessionStateStoreData
存储在AppFabric Cache中。
这是反射的代码
[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()
{
...
}
}
当你尝试在web上下文之外获取会话项时,AppFabric缓存客户端无法反序列化数据项,因为它是以未知类型序列化的(在Microsoft.Web.DistributedCache.dll中定义)。
添加一个引用到Microsoft.Web.DistributedCache.dll
这也需要System.Web.dll,因为它需要System.Web.SessionState.SessionStateStoreData