나는 당신의 접근 방식에 약간 혼란 스럽다. 직렬화 자체가 실제로 데이터를 유지하지 않습니다. 아마도 그것은 당신의 문제입니다. 필자는 XML을 IsolatedStorage에 저장하는 것이 데이터를 유지하는 쉬운 방법 중 하나임을 발견했습니다.
XDocument 개체를 저장하기 위해 이와 비슷한 IsolatedStorage 클래스를 만들었습니다.
public static void SaveDataToIsolatedStorage(string filePath, FileMode fileMode, XDocument xDoc)
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream location = new IsolatedStorageFileStream(filePath, fileMode, storage))
{
System.IO.StreamWriter file = new System.IO.StreamWriter(location);
xDoc.Save(file);
}
}
}
여기 내 독자입니다.
private static XDocument ReadDataFromIsolatedStorageXmlDoc()
{
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!storage.FileExists(filePath))
{
return new XDocument();
}
using (var isoFileStream = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, storage))
{
using (XmlReader reader = XmlReader.Create(isoFileStream))
{
return XDocument.Load(reader);
}
}
}
}