I am creating a application in Windows Phone 7 Mango, and when I load up the application, the MainViewModel loads all the info from a file in isolated storage, with this function:
private ObservableCollection<KasutajadViewModel> LoadUsers()
{
ObservableCollection<KasutajadViewModel> kasutajad = new ObservableCollection<KasutajadViewModel>();
try
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Kasutajad.xml", FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<PiletViewModel>));
//ObservableCollection<KasutajadViewModel> data
kasutajad =
(ObservableCollection<KasutajadViewModel>)serializer.Deserialize(stream);
stream.Close();
}
}
}
catch (Exception)
{
}
return kasutajad;
}
Problem is, that the deserializer doesn't return the data. Even when the XML file it reads from is like this:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfKasutajadViewModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<KasutajadViewModel>
<Nimi>Reigo Hein</Nimi>
<Isikukood>96952422597</Isikukood>
</KasutajadViewModel>
</ArrayOfKasutajadViewModel>
That is produced by a SaveUsers function, but I think this is redundant for the problem. The LoadUsers loads the stream correctly, but the deserialization doesn't output the required data.
Hope anyone can help me, thank you.
You're creating a XmlSerializer for an ObservableCollection of PiletViewModel
, yet you're deserializing an array of KasutajadViewModel
. There's a type inconsistency here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.