我正在尝试将对象保存到隔离存储中但收到A first chance exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred in System.Runtime.Serialization.ni.dll
我的对象类
[DataContract]
public class NoteContent : IEnumerable
{
[DataMember]
public Microsoft.Phone.Controls.SupportedPageOrientation SupportedOrientation{ get; set; }
[DataMember]
public List<Character> NoteCharacterList { get; set; }
[DataMember]
public string NoteFileName { get; set; }
private List<Character> notecontent = new List<Character>();
public void Add(Character charObj)
{
notecontent.Add(charObj);
NoteCharacterList = notecontent;
}
public void Clear()
{
notecontent.Clear();
}
public Character this[int id]
{
get { return notecontent[id]; }
}
public IEnumerator<Character> GetEnumerator()
{
return notecontent.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
我用来序列化和保存对象的代码。在这一行引发了错误_mySerializer.WriteObject(targetFile, sourceData);
public void SaveMyData(NoteContent sourceData, String targetFileName)
{
string TargetFileName = String.Format("{0}/{1}.dat", TargetFolderName, targetFileName);
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!store.DirectoryExists(TargetFolderName))
store.CreateDirectory(TargetFolderName);
try
{
using (var targetFile = store.CreateFile(TargetFileName))
{
_mySerializer.WriteObject(targetFile, sourceData);
}
}
catch (Exception e)
{
store.DeleteFile(TargetFileName);
}
}
}
该对象包含对象和控件的列表。
要保存的主对象内的对象列表
是因为我无法序列化图像控件和画布控件等对象吗?将此类对象保存到隔离存储中的最佳方法是什么?
更新 1
我已将对象简化为仅包含以下属性,但仍然出现相同的错误。Points 和 Char 可以序列化吗?
public Point ImagePosition { get; set; }
public Char CharText { get; set; }
public double ImageDegree { get; set; }
public double ImageScale { get; set; }
public int ImageZOrder { get; set; }
public bool IsResizeCancel { get; set; }
public double MaxSliderValue { get; set; }
public double CurrentWidth { get; set; }
public double CurrentHeight { get; set; }