Isolated Storage security exception on windows phone

廉价感情. 提交于 2019-12-06 05:11:33

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:

    var data = (IEnumerable<MyDataType>)listBox1.ItemsSource; // perform the cast to get the correct type;
    settings.Add("list", data.ToArray()));
    settings.Save();

This way, it's in a nice clean datatype for the serializer.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!