0
我從隔離儲存讀取對象用下面的代碼:錯誤讀取序列化對象? WP7
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屬性與我的對象一起存儲。任何建議將不勝感激!謝謝!
我正在存儲一個包含Song屬性的對象。當我從獨立存儲中讀取對象時,我需要讀取Song屬性。 – andersra 2010-12-06 01:42:18