Serialization 读取序列化对象时出错?WP7

Serialization 读取序列化对象时出错?WP7,serialization,exception-handling,windows-phone-7,isolatedstorage,Serialization,Exception Handling,Windows Phone 7,Isolatedstorage,我正在使用以下代码从独立存储中读取对象: public static T Load<T>(string name) where T : class, new() { T loadedObject = null; using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication()) using (IsolatedStor

我正在使用以下代码从独立存储中读取对象:

public static T Load<T>(string name) where T : class, new()
    {
        T loadedObject = null;
        using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
        using (IsolatedStorageFileStream storageFileStream = new IsolatedStorageFileStream(name, System.IO.FileMode.OpenOrCreate, storageFile))
        {
            if (storageFileStream.Length > 0)
            {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(T));
                    loadedObject = serializer.ReadObject(storageFileStream) as T; //####Error Here####
            }
            if (loadedObject == null)
            {
                loadedObject = new T();
            }
        }
在读取我的对象时,我得到一个SecurityException,它读取

无法在部分信任中反序列化类型“Microsoft.Xna.Framework.Media.Song”,因为它没有公共无参数构造函数

正在读取的我的对象类包含一个Song属性,该属性引发上述错误

有办法解决这个问题吗?我希望我的歌曲属性与我的对象一起存储。任何建议都将不胜感激!谢谢

你的目标是什么

你想在应用程序中播放一首歌吗? 您是否在应用程序中创建歌曲? 您想访问歌曲库吗? 你想从网上得到这首歌吗? @我只需在你的项目中为你的内容添加一首歌曲。不需要使用序列化。 @2使用内存流对其进行维护。保存它,然后加载流。使用MediaElement.SetSourceStream流 @3使用 @4宋宋=宋。FromUri

您需要以不同的方式存储它。例外解释了为什么在这种情况下,一首歌是一个糟糕的选择

看看这个例子。

我正在存储一个包含歌曲属性的对象。当我从独立存储中读取对象时,我要求读取Song属性。你是说使用我当前的方法无法解决此问题吗?我现在意识到,不存储歌曲,而是将索引存储在我的MediaLibrary.Songs中。现在我可以加载我的对象并重置所有歌曲属性。