Windows phone 7 序列化PhoneApplicationPage Windows Phone
我有一个名为“Conexion”的类,我把我的应用程序的所有信息都保存在那里,当用户按下windows键时,我希望它将该类的对象保存到一个文件中,但是该应用程序崩溃了,因为它说obect“delegado”有一个反映其类型的问题。此对象的类型为“PhoneApplicationPage”,似乎无法序列化。对象跟踪请求的页面 因此,我请求您的帮助,看看是否有一个解决方案,这不会使我重做的应用程序,因为我没有时间 下面是我用来保存和加载数据的方法代码Windows phone 7 序列化PhoneApplicationPage Windows Phone,windows-phone-7,xml-serialization,Windows Phone 7,Xml Serialization,我有一个名为“Conexion”的类,我把我的应用程序的所有信息都保存在那里,当用户按下windows键时,我希望它将该类的对象保存到一个文件中,但是该应用程序崩溃了,因为它说obect“delegado”有一个反映其类型的问题。此对象的类型为“PhoneApplicationPage”,似乎无法序列化。对象跟踪请求的页面 因此,我请求您的帮助,看看是否有一个解决方案,这不会使我重做的应用程序,因为我没有时间 下面是我用来保存和加载数据的方法代码 public void save() {
public void save() {
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream stream = storage.CreateFile(fileName);
DateTime currTime = DateTime.Now;
this.timeOff = currTime.ToString();
XmlSerializer xml = new XmlSerializer(this.GetType());
xml.Serialize(stream, this);
stream.Close();
stream.Dispose();
}
public Conexion load() {
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
Conexion conn;
if (storage.FileExists(fileName))
{
IsolatedStorageFileStream stream = storage.OpenFile(fileName, System.IO.FileMode.Open);
XmlSerializer xml = new XmlSerializer(typeof(Conexion));
conn = xml.Deserialize(stream) as Conexion;
stream.Close();
DateTime currTime = DateTime.Now;
DateTime checkTime = DateTime.Parse(timeOff).AddMinutes(lapso);
if (DateTime.Compare(checkTime, currTime) >= 0)
{
Console.WriteLine("sesion valida");
}
else {
conn.reseteaSingletonConexion();
}
stream.Dispose();
}
else
{
conn= new Conexion();
}
return conn;
}
提前谢谢
编辑:
忽略对象“delegado”使应用程序停止崩溃,但现在,当我加载信息时,该对象无法反序列化,它似乎在同一错误中标记了两个细节:
There is an error in XML document (2, 2).
Conexion cannot be serialized because it does not have a parameterless constructor.
但该类确实有一个无参数构造函数
有什么想法吗?您可以对不会序列化的对象使用
[XmlIgnore]
属性(很可能您不想序列化整个XAML页面)
将此属性置于Conexion
类中的属性之上。例如
public class Conexion
{
public string MyPropertyToSerialize { get;set; }
[XmlIgnore]
public string MyPropertyToIgnore { get;set; }
}
希望这能有所帮助。谢谢你阻止了应用程序崩溃,但现在我无法反序列化对象。你能在你的问题中提供完整的Conexion类吗?