Windows Phone 上的隔离存储安全异常
我试图保留一些数据,但这里出现错误。
中的独立存储声明
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
onNavigedFrom 的公共部分主页类实现
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
settings.Add("list",listBox1.ItemsSource);
settings.Save();
}
当我点击模拟器上的开始按钮时,我收到一个安全异常:
System.Security.SecurityException was unhandled
Message=SecurityException
我的列表框绑定到来自 xml 的数据。我正在使用 linq to xml 来读取它。
我在这里读到了类似的问题:使用独立存储时未处理SecurityException
但我无法理解这个人的意思“存储的类需要标记为不允许的公共内部”。
任何帮助都会很好。谢谢!
Im trying to persist some data but im getting an error here.
Declaration of isolated storage inside my public partial mainpage class
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
implementation of onNavigatedFrom
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
settings.Add("list",listBox1.ItemsSource);
settings.Save();
}
When I hit the start button on the emulator I get a security exception:
System.Security.SecurityException was unhandled
Message=SecurityException
My listbox is binded to data coming from a xml. I´m using linq to xml to read it.
I have read a similar question here: SecurityException was unhandled when using isolated storage
But I could not understand what the person meant with "stored class needs to be marked public internals not allowed".
Any help would be nice. Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
保存到设置时,需要有明确的数据类型。在本例中,您只是保存 ItemsSource,但项目源中实际有什么?该数据需要公开,以便序列化器可以对其进行序列化。 ListBox 中有哪些数据?它是如何定义的?
IEnumerable(本身)也无法序列化,因为序列化程序需要知道将其序列化为什么类型。
我推荐这样的代码:
这样,它对于序列化器来说是一个很好的干净的数据类型。
When you save to the settings, you need to have a clear data type. In this case, you're just saving the ItemsSource, but what is actually in the items source? That data needs to be publically knowable so that the serializer can serialize it. What data is in the ListBox? How is it defined?
An IEnumerable (as such) also cannot be serialized, because the serializer needs to know what type to serialize it as.
I'd recommend code like this:
This way, it's in a nice clean datatype for the serializer.
分配给
listbox1.ItemsSource
的对象集合是什么?我的猜测是,这是无法序列化的东西。 SecurityException 将指示无法完成序列化,因为它是一个非公开的类。
更改类的可访问性并确保它可以序列化。
What is the object collection assigned to
listbox1.ItemsSource
?My guess is that it's something that can't be serialized. The SecurityException would indicate the the serialization can't be done because it's a class that's not public.
Change the accessibility of the class and ensure it can be serialized.