mscorlib.ni.dll中出现“System.InvalidOperationException”类型的异常,但未在用户代码

时间:2016-07-12 08:37:13

标签: c# data-binding

我无法弄清楚为什么在执行第二个语句时调用GetData()方法会出现此错误。它产生以下错误:

  

mscorlib.ni.dll中出现“System.InvalidOperationException”类型的异常,但未在用户代码中处理

其他信息:XML文档(0,0)中存在错误。“,请帮助!!!

public async void GetData()
{
    Serializer("data1.xml");
    dm = new DataModel() { View_Model = await Deserializer("data1.xml") };
}  

public async Task<List<ViewModel>> Deserializer(string FileName)
{
    var stream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync(FileName);
    XmlSerializer deserializer = new XmlSerializer(typeof(List<ViewModel>));
    var x = new ViewModel();
    List<ViewModel> vm = new List<ViewModel>();
    using (stream)
    {
        vm = (List<ViewModel>)deserializer.Deserialize(stream);

    }

    return vm;
}

public async void Serializer(string FileName)
{
    var stream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(FileName,CreationCollisionOption.OpenIfExists);

    DataContractSerializer serializer = new DataContractSerializer(typeof(ViewModel));

    XmlSerializer ser = new XmlSerializer(typeof(ViewModel));

    var x = new ViewModel();

    x.D_model = new Dmodel[] { new Dmodel() { title="Google",uri= "http://www.englishmonarchs.co.uk/images/plantagenet/windsr_22.jpg" } };
    using (stream)
    {

        ser.Serialize(stream, x);
    }                    
}

0 个答案:

没有答案