gpt4 book ai didi

serialization - 如何调试逻辑删除的 WP7 应用程序中的序列化错误

转载 作者:行者123 更新时间:2023-12-04 06:06:18 25 4
gpt4 key购买 nike

我在 OnNavigatedFrom 和 To 事件中处理我的 WP7 应用程序的当前状态,这样如果应用程序被逻辑删除或者它们导航到不同的页面,它会将状态保存到内置的 PhoneApplicationService 状态。

我有一个简单的 ViewModel which I dump to the state让生活更轻松。当导航到我的应用程序中的不同页面时,状态存储良好并且恢复正常(即我假设它此时正在序列化)。但是,当我tombstone 应用程序(即“开始”按钮)时,我遇到了一个未处理的序列化错误,堆栈跟踪没有给我任何失败原因的线索。

我已经尝试将实际调用包装在一个 try catch block 中以尝试查看问题出在哪里,但它无济于事 - 这是运行时在使用我的对象进行逻辑删除时所做的事情不同于它只是将它存储在页面之间.

这是我的代码:

protected override void OnNavigatedFrom(NavigationEventArgs args)
{
appService.State["TournamentViewModel"] = tournamentViewModel;
base.OnNavigatedFrom(args);
}

protected override void OnNavigatedTo(NavigationEventArgs args)
{
if (appService.State.ContainsKey("TournamentViewModel"))
{
tournamentViewModel = (TournamentViewModel)appService.State["TournamentViewModel"];
}
base.OnNavigatedTo(args);
}

这是生成的错误 - 我真的不知道问题出在哪里 - 我怎样才能更好地调试它?

异常信息:消息:“SecurityException”InnerException:“无法计算表达式”

堆栈跟踪:

   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateGetOnlyCollectionDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetGetOnlyCollectionDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.DataContract.GetGetOnlyCollectionDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XmlObjectSerializerContext.GetDataContractSkipValidation(Int32 typeId, RuntimeTypeHandle typeHandle, Type type)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithXsiType(XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerialize(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.InternalSerializeReference(XmlWriterDelegator xmlWriter, Object obj, Boolean isDeclaredType, Boolean writeXsiType, Int32 declaredTypeID, RuntimeTypeHandle declaredTypeHandle)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Runtime.Serialization.XmlFormatWriter.InternalSerialize(MethodInfo methodInfo, Object memberValue, Type memberType, Boolean writeXsiType, XmlObjectSerializerWriteContext context, XmlWriterDelegator xmlWriter)
at System.Runtime.Serialization.XmlFormatWriter.WriteValue(Type memberType, Object memberValue, Boolean writeXsiType, XmlObjectSerializerWriteContext context, XmlWriterDelegator xmlWriter)
at System.Runtime.Serialization.XmlFormatWriter.WriteMember(SerializingObject serObj, Int32 memberIndex, ClassDataContract derivedMostClassContract)
at System.Runtime.Serialization.XmlFormatWriter.WriteClass(CallStackElement`1 callStackElement)
at System.Runtime.Serialization.XmlFormatWriter.Serialize(XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.XmlFormatWriter.InitializeCallStack(XmlWriterDelegator xmlWriterDel, Object obj, XmlObjectSerializerWriteContext writeContext, DataContract contract)
at System.Runtime.Serialization.CollectionDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializerWriteContext context)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteDataContractValue(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.XmlObjectSerializerWriteContext.SerializeWithoutXsiType(DataContract dataContract, XmlWriterDelegator xmlWriter, Object obj, RuntimeTypeHandle declaredTypeHandle)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(Stream stream, Object graph)
at Microsoft.Phone.Shell.StreamPersister.Serialize(IDictionary`2 dictionary, IEnumerable`1 knownTypes)
at Microsoft.Phone.Shell.StreamPersister.Save(ShellPageManager shellPageManager, String key, IDictionary`2 dictionary, IEnumerable`1 knownTypes)
at Microsoft.Phone.Shell.PhoneApplicationService.FireDeactivated()
at Microsoft.Phone.Execution.NativeEmInterop.FireOnPause()

更新:通过反复试验,我发现问题出在 AppBar,它似乎不可序列化。我用 [IgnoreDataMember] 标记它,它现在在 different problem 上抛出一个更有意义的错误.我仍然想知道是否有任何简单的方法可以获取此信息...

最佳答案

罗德尼,

我的理解是,当您将一个对象放入两个状态字典之一(一个来自 PhoneApplicationPage,另一个来自 PhoneApplicationServices)时,它不会立即序列化或反序列化。

如果您使用 Page.State 存储数据,它会在您离开页面时序列化您的状态包,并在您返回页面时反序列化(而不是在您从状态包中添加或读取对象时)。

如果您使用 PhoneApplicationService.State,序列化会在您逻辑删除时发生,反序列化会在应用程序重新激活时发生(尽管我不确定这是否与 PhoneApplicationService.Activated 事件有关)。

顺便说一句,Page.State 不允许在页面之间共享数据。保存到 PhoneApplicationService.State 允许您这样做。

IsolatedStorage.AppSettings 似乎默默地处理反序列化问题,所以我不确定它何时会发生。然而,序列化发生在您调用 Save() 时。

詹姆斯

关于serialization - 如何调试逻辑删除的 WP7 应用程序中的序列化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3975652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com