Hi Rocky,
I have spent almost 20 hours on this issue. Can you help me please?
I am trying to serialize and deserialize a class called ReturnCriteria which is inherited from CSLA.CriteriaBase.
The serialization is working fine and I have seen the xml. This is the method for serialization:
public static void SaveData<T>(string guid, T data)
{
DeleteData();
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(guid, FileMode.Create, isf))
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.NewLineChars = string.Empty;
settings.Indent = false;
settings.NewLineHandling = NewLineHandling.None;
using (XmlWriter xmlwriter = XmlWriter.Create(isfs, settings))
{
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
serializer.Serialize(xmlwriter, data, namespaces);
}
}
}
}
But for deserialization it gives me an exception:
{System.Security.VerificationException: Operation could destabilize the runtime.
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderTaxReturnListControllerCriteria.Read5_Item(Boolean
isNullable, Boolean checkType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderTaxReturnListControllerCriteria.Read6_Item()}
Here is the code for Deserialization:
private static T LoadData<T>(string guid)
{
T data = default(T);
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(guid, FileMode.Open, isf))
{
XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));
var obj = serializer.Deserialize(isfs);
}
}
catch
{
}
}
return data;
}
Note: This code is saving and retreiving the data from IsolatedStorage of silverlight.
↧
Deserialization of CriteriaBase class
↧