まず第一に、説明は多くのコードで少し長いかもしれませんが、できる限りの情報を提供したくありません。私は自分のアプリのトゥームストーンを使用しており、シリアル化されたクラスを保存したいと考えています:
[DataContract]
private class Tombstone
{
[DataMember]
public UserDetails UserProfile { get; set; }
}
// Create instance of the tombstone class
private Tombstone _tombstone;
public ProfileSetup()
{
_tombstone = new Tombstone();
}
//Add data to userProfile
void UserInformationAccess_OnGetUserDetailsComplete(GetUserDetailsResponse response)
{
_tombstone.UserProfile = response.userDetails;
}
そして、ナビゲートされたものには例外があります... まさにここにあります:
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
if (_tombstone != null)
this.SaveState("tombstone", _tombstone);
}
//The state manager class
public static class StateManager
{
/// <summary>
/// Saves a key-value pair into the state object
/// </summary>
/// <param name="phoneApplicationPage">The phone application page.</param>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public static void SaveState(this PhoneApplicationPage phoneApplicationPage, string key, object value)
{
if (phoneApplicationPage.State.ContainsKey(key))
{
phoneApplicationPage.State.Remove(key);
}
phoneApplicationPage.State.Add(key, value);
}
}
そして今、例外が来ていることに気をつけてください:
「セキュリティ例外」 System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract (Int32 id、RuntimeTypeHandle typeHandle、型の種類) で System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation (Int32 id、RuntimeTypeHandle typeHandle、型の種類) で System.Runtime.Serialization.DataContract.GetDataContractSkipValidation (Int32 id、RuntimeTypeHandle typeHandle、型の種類) で System.Runtime.Serialization.DataContract.GetDataContract (RuntimeTypeHandle typeHandle、型の種類、SerializationMode モード) で System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContract (RuntimeTypeHandle typeHandle、型の種類) で System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType (XmlWriterDelegator xmlWriter、オブジェクト obj、RuntimeTypeHandle objectTypeHandle、型 objectType、Int32 宣言型 ID、RuntimeTypeHandle 宣言型ハンドル、型宣言型) で System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize (XmlWriterDelegator xmlWriter、オブジェクト obj、ブール型 isDeclaredType、ブール型 writeXsiType、Int32 宣言型 ID、RuntimeTypeHandle 宣言型ハンドル) で System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference (XmlWriterDelegator xmlWriter、オブジェクト obj、ブール値の isDeclaredType、ブール値の writeXsiType、Int32 definedTypeID、RuntimeTypeHandle 宣言されたタイプハンドル) で System.Reflection.RuntimeMethodInfo.InternalInvoke (RuntimeMethodInfo rtmi、オブジェクト obj、BindingFlags invokeAttr、バインダー バインダー、オブジェクト パラメーター、CultureInfo カルチャ、ブール値の isBinderDefault、アセンブリの呼び出し元、ブール値の verifyAccess、StackCrawlMark & stackMark) で System.Reflection.RuntimeMethodInfo.InternalInvoke (オブジェクト obj、BindingFlags invokeAttr、バインダー バインダー、オブジェクト [] パラメーター、CultureInfo カルチャ、StackCrawlMark & stackMark) で System.Reflection.MethodBase.Invoke (オブジェクト obj、オブジェクト [] パラメーター) で System.Runtime.Serialization.XmlFormatWriter.InternalSerialize (MethodInfo methodInfo、オブジェクト memberValue、型 memberType、ブール値の writeXsiType、XmlObjectSerializerWriteContext コンテキスト、XmlWriterDelegator xmlWriter) で System.Runtime.Serialization.XmlFormatWriter.WriteValue (型 memberType、オブジェクト memberValue、ブール値の writeXsiType、XmlObjectSerializerWriteContext コンテキスト、XmlWriterDelegator xmlWriter) で System.Runtime.Serialization.XmlFormatWriter.WriteMember (SerializingObject serObj、Int32 memberIndex、ClassDataContract 派生MostClassContract) で System.Runtime.Serialization.XmlFormatWriter.WriteClass (CallStackElement`1 callStackElement) で System.Runtime.Serialization.XmlFormatWriter.Serialize (XmlObjectSerializerWriteContext コンテキスト) で System.Runtime.Serialization.XmlFormatWriter.InitializeCallStack (XmlWriterDelegator xmlWriterDel、オブジェクト obj、XmlObjectSerializerWriteContext writeContext、DataContract コントラクト) で System.Runtime.Serialization.CollectionDataContract.WriteXmlValue (XmlWriterDelegator xmlWriter、オブジェクト obj、XmlObjectSerializerWriteContext コンテキスト) で System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue (DataContract dataContract、XmlWriterDelegator xmlWriter、オブジェクト obj、RuntimeTypeHandle definedTypeHandle) で System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType (DataContract dataContract、XmlWriterDelegator xmlWriter、オブジェクト obj、RuntimeTypeHandle definedTypeHandle) で System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent (XmlWriterDelegator ライター、オブジェクト グラフ) で System.Runtime.Serialization.DataContractSerializer.InternalWriteObject (XmlWriterDelegator ライター、オブジェクト グラフ) で System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions (XmlWriterDelegator ライター、オブジェクト グラフ) で System.Runtime.Serialization.XmlObjectSerializer.WriteObject (XmlDictionaryWriter ライター、オブジェクト グラフ) で System.Runtime.Serialization.XmlObjectSerializer.WriteObject (ストリーム ストリーム、オブジェクト グラフ) で Microsoft.Phone.Shell.StreamPersister.Serialize (IDictionary`2 辞書、IEnumerable`1 knownTypes) で Microsoft.Phone.Shell.StreamPersister.Save (ShellPage shellPage、文字列キー、IDictionary`2 ディクショナリ、IEnumerable`1 knownTypes) で Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedFrom (NavigationEventArgs e) で System.Windows.Navigation.NavigationService.RaiseNavigated (オブジェクト コンテンツ、Uri uri、NavigationMode モード、ブール値 isNavigationInitiator、PhoneApplicationPage existingContentPage、PhoneApplicationPage newContentPage) で System.Windows.Navigation.NavigationService.Journal_NavigatedExternally (オブジェクトの送信者、JournalEventArgs args) で System.Windows.Navigation.Journal.OnNavigatedExternally (文字列名、Uri uri、NavigationMode モード) で System.Windows.Navigation.Journal.ShellPage_NavigatedAway (オブジェクトの送信者、NavigateAwayEventArgs 引数) で Microsoft.Phone.Shell.Interop.ShellPageCallback.FireOnNavigateAway (IntPtr thisPage、方向方向、IntPtr pageNext) で
私はこれに関連して多くのことを調査しましたが、私は空っぽになりました:(どんな助けも感謝しています.
[編集]
問題のような縫い目は、TombStone クラスにプライベートなアクセシビリティがあることでした。それを変更しました...しかし、次の例外が発生しました。
データ コントラクト名が 'ArrayOfKeyValueOfstringJTokeneJCYCtcq:http://schemas.microsoft.com/2003/10/Serialization/Arrays' の 'Newtonsoft.Json.Linq.JObject' は予期されていません。たとえば、KnownTypeAttribute 属性を使用するか、DataContractSerializer に渡される既知の型のリストにそれらを追加することにより、静的に認識されていない型を既知の型のリストに追加します。
ここにも UserDetails クラスがあります
[KnownType(typeof(Phone[]))]
[KnownType(typeof(UserInterest<InterestCategory?, object>))]
[KnownType(typeof(UserInterest<InterestCategory?, object>[]))]
[DataContract]
public class UserDetails
{
/// <summary>
/// Specifies an identifier of user
/// </summary>
///
[DataMember]
public long userId { get; set; }
/// <summary>
/// Specifies a nick of user
/// </summary>
///
[DataMember]
public string nick { get; set; }
/// <summary>
/// Specifies a full name of user. The field is absent if it has null value
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string fullName { get; set; }
/// <summary>
/// Specifies a gender of user. The field is absent if it has null value
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(EnumAttributeConverter<Gender>))]
[DataMember]
public Gender? gender { get; set; }
/// <summary>
/// Specifies a birthday of user as string in dd.MM.yyyy format.
/// The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string birthday { get; set; }
/// <summary>
/// Specifies an e-mail of user. The field is absent if it has null value
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string email { get; set; }
/// <summary>
/// Specifies a website of user. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string website { get; set; }
/// <summary>
/// Specifies a general information about user. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string about { get; set; }
/// <summary>
/// Specifies a place of birth for user. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public Address<Country?>? homeAddress { get; set; }
/// <summary>
/// Specifies a place of residence for user. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public Address<Country?>? currentAddress { get; set; }
/// <summary>
/// Specifies a list of user's phones. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public Phone[] phones { get; set; }
/// <summary>
/// Specifies an URI of avatar of profile. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string avatar { get; set; }
/// <summary>
/// Specifies a job. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string job { get; set; }
/// <summary>
/// Specifies a mood status of user as a color.The field is absent in read commands if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public int? mood { get; set; }
/// <summary>
/// Specifies a relationship status of user.The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public RelationshipStatus? relationshipStatus { get; set; }
/// <summary>
/// Defines a discovery purpose specified by user.The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public DiscoveryPurpose? discoveryPurpose { get; set; }
/// <summary>
/// Specifies a list of user interests. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public UserInterest<InterestCategory?, object>[] interests { get; set; }
/// <summary>
/// Specifies a status of user. The field is absent if it has null value.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public string status { get; set; }
/// <summary>
/// Specifies an availability status of user.
/// </summary>
[JsonConverter(typeof(EnumAttributeConverter<AvailabilityStatus>))]
[DataMember]
public AvailabilityStatus availabilityStatus { get; set; }
/// <summary>
/// Specifies a location of user. The field is absent if location is undefined.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public Location location { get; set; }
/// <summary>
/// Defines if the given user and the requestor interacted previously.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
[DataMember]
public bool interacted { get; set; }
/// <summary>
/// Defines the status of pending friendship request if it exists.
/// Equals NONE if there is no pending friendship request.
/// Equals PENDING_IN if the given user sent friendship
/// request to the user (requestor) who requests extended
/// information.
/// Equals PENDING_OUT if the requestor sent friendship
/// request to the given request.
/// </summary>
[JsonConverter(typeof(EnumAttributeConverter<FriendshipRequestStatus>))]
[DataMember]
public FriendshipRequestStatus friendshipRequestStatus { get; set; }
/// <summary>
/// Defines if the given user was ignored by the requestor.
/// </summary>
///
[DataMember]
public bool ignored { get; set; }
}