访问IsolatedStorage时发生错误 [英] An error occurred while accessing IsolatedStorage

查看:67
本文介绍了访问IsolatedStorage时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好群组。

我正在使用下面的代码反序列化几个集合类而没有任何问题。 现在我正在使用它反序列化单个类,我在消息框中收到错误"访问IsolatedStorage时出错"。 代码仍然有效,
我的班级已经重新调整,但错误是什么?  XML看起来很好。  我该怎么调试呢?

Hi. 
I'm using the code below to deserialize a few collection classes with no problems.  Now I'm using it to deserialize a single class and I get the error in a messagebox "An error occurred while accessing IsolatedStorage".  The code still works, my class is reinstanciated, but what's the error?  The XML looks fine.   How do I debug this even?

public object DeserializeXMLtoObject(string fileName, Type newClassType) { try { IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); XmlSerializer x = new XmlSerializer(newClassType); StreamReader objStreamReader = new StreamReader(myIsolatedStorage.OpenFile(fileName, FileMode.Open));

////此行导致错误////
dynamic newClass = x.Deserialize(objStreamReader);
//////// ////////////////////////////


objStreamReader.Close();

返回newClass;

}
catch(IsolatedStorageException iso)
{
MessageBox.Show(" DeserializeXMLtoObject中的错误:" + fileName +" - " + iso。信息);
返回null;
}
catch(Exception ex)
{
MessageBox.Show(" DeserializeXMLtoObject中的错误:" + ex.Message);
返回null;
}


}

//// THIS LINE CAUSES THE ERROR //// dynamic newClass = x.Deserialize(objStreamReader);
////////////////////////////////////
objStreamReader.Close(); return newClass; } catch (IsolatedStorageException iso) { MessageBox.Show("Error in DeserializeXMLtoObject: " + fileName + " - " + iso.Message); return null; } catch (Exception ex) { MessageBox.Show("Error in DeserializeXMLtoObject: " + ex.Message); return null; } }

推荐答案

如果你的简单课程有效,你的序列化XML可能有问题。 查看XMLSerializer的限制,看看您的新类中是否存在不受支持或需要特殊考虑的内容。您可以尝试
a不同的序列化程序,例如DataContractSerializer。

There probably is something wrong in your serialized XML if your simpler class worked.  Look up the limitations of the XMLSerializer and see if there is something in your new class that is not supported or needs special consideration. You could try a different serializer such as DataContractSerializer.

这里
是一个比较。

-Mark


这篇关于访问IsolatedStorage时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆