Pergunta

We have a web application which is storing frequently using data in cache memory.
Earlier it was HttpRuntime Cache, but later migrated to AppFabric Cache.
After the migration, it throws the following error while trying to add an object into Cache:
Error:

System.Runtime.Serialization.SerializationException:
"There was an error deserializing the object of type 
System.Collections.ArrayList. No set method for property '' in type ''."

Adding to HttpRuntime Cache is working still. But to AppFabric Cache throws the above error.

Code Snippet for adding item to Cache memory:

public static void Add(string pName, object pValue)
{
  //System.Web.HttpRuntime.Cache.Add(pName, pValue, null, DateTime.Now.AddSeconds(60), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
 appFabricCache.Add(pName, pValue);
}

Instance of the following class is trying to store in Cache Memory.

 public class Kernel
 {
 internal const BusinessObjectSource BO_DEFAULT_SOURCE=BusinessObjectSource.Context;
 private System.Collections.ArrayList mProcesses = new System.Collections.ArrayList();
 private System.Collections.Hashtable mProcessesHash = new System.Collections.Hashtable();

 public SnapshotProcess mSnapShotProcess ;
 private System.Collections.ArrayList mErrorInformation;

 public Collections.ArrayList Processes
 {
   get { return mProcesses; }
 }
}

Anybody knows how to resolve this issue......? Thanks.

Foi útil?

Solução

Objects are stored in the AppFabric cache in a serialized form. This means that every objects must be Serializable. AppFabric internally uses the NetDataContractSerializer.

When working with HttpRuntime Cache, you keep only a reference in the cache and objects are not serialized.

System.Collections.ArrayList (very old class) is serializable but every nested/children have to be serializable too. So change your code (Kernel and nested/children Type) in this way.

Here is a piece of code to test Serialization without AppFabric.

// requires following assembly references:
//
//using System.Xml;
//using System.IO;
//using System.Runtime.Serialization;
//using System.Runtime.Serialization.Formatters.Binary;
//
// Target object “obj”
//
long length = 0;

MemoryStream stream1 = new MemoryStream();
using (XmlDictionaryWriter writer = 
    XmlDictionaryWriter.CreateBinaryWriter(stream1))
{
    NetDataContractSerializer serializer = new NetDataContractSerializer();
    serializer.WriteObject(writer, obj);
    length = stream1.Length; 
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top