Is there a way to to serialize class asynchronously? I'm asking becouse when my program is trying to do this:
public static async void Serialize(List<Zajecia> xml_List)
{
using (var stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync("Plan list.xml", CreationCollisionOption.ReplaceExisting))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Zajecia>));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, new XmlWriterSettings() { Indent = true }))
{
serializer.Serialize(xmlWriter, xml_List);
}
}
}
Class:
public class Zajecia
{
public string c { get; set; }
public string p { get; set; }
public Zajecia ()
{}
public Zajecia(string C, string P)
{
c = C;
p = P;
}
}
My async serialization is used in navigation function:
protected override async Task OnNavigatedTo(NavigationEventArgs e)
{
string t = e.Parameter as string;
if (!string.IsNullOrEmpty(t))
{
string[] _p = new string[10];
_p = t.Split('^');
_lista.Add(new Zajecia(t,( _p[3]+"("+_p[5]+")")));
Dodaj_zajecia(_p);
await Serialize(_lista);
}
else
base.OnNavigatedTo(e);
}
I get only this error instead of serialization of anything:
System.Runtime.InteropServices.WindowsRuntime.RuntimeClass is inaccessible due to its protection level. Only public types can be processed.
Everything is public in my program and still it doesn't help. Any ideas how to make it work?