简体   繁体   中英

IsolateStorage Issue in WP7

I am facing the problem regarding the following issue in wp7

"Type 'System.Windows.Media.Transform' cannot be serialized in C#"

When i call the below method to save my List data to isolated storage

SerializeHelper.SaveSetting("myfile.Xml",swaplist);

then then i am getting the exception.

public static class SerializeHelper
    {
        public static void SaveSetting<T>(string fileName, T dataToSave)
        {
            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                try
                {
                    using (var stream = store.CreateFile(fileName))
                    {
                        var serializer = new DataContractSerializer(typeof(T));
                        serializer.WriteObject(stream, dataToSave);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                    return;
                }
            }
        }

    }

I am attaching the screenshot of structure of list data 在此处输入图片说明

How to resolve this?

Thank you for adding the screenshot... and pasting some code. Can't really see anything wrong.

does you VM only expose public primitive / serialisable types ? I have in past used something like this to serialise to iso store.

public static void SaveObjectToStorage<T>(T ObjectToSave)
{
    TextWriter writer;

    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream fs = isf.OpenFile(GetFileName<T>(), System.IO.FileMode.Create))
        {
            writer = new StreamWriter(fs);
            XmlSerializer ser = new XmlSerializer(typeof(T));
            ser.Serialize(writer, ObjectToSave);
            writer.Close();
        }

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM