C# 调用SuspendionManager.SaveAsync()时发生异常
我正在构建一个Windows 8应用程序,出现了以下异常:C# 调用SuspendionManager.SaveAsync()时发生异常,c#,exception,windows-8,facebook-c#-sdk,C#,Exception,Windows 8,Facebook C# Sdk,我正在构建一个Windows 8应用程序,出现了以下异常: mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task) + 0x5e bytes mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotificatio
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task) + 0x5e bytes
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) + 0x35 bytes
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x16 bytes
FacebookRandomizer.exe!FacebookRandomizer.App.OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) Line 86 + 0xa5 bytes C#
[Native to Managed Transition]
暂停管理器失败
运行以下代码时:
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
await SuspensionManager.SaveAsync();
deferral.Complete();
}
异常发生在方法的第三行,它实际上没有给出任何细节
我在网上找不到任何有用的东西。以前有人见过这个吗
//编辑
这可能与我正在为Windows8Facebook SDK使用dynamic
type变量有关
是否不允许动态变量
//编辑2
以下是动态变量的用法:
dynamic result = await FB.GetTaskAsync("fql", parameters);
if (result.data.Count > 0)
{
return result.data[0].src_big as string;
}
以及异常的调用堆栈:
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task task) + 0x5e bytes
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task) + 0x35 bytes
mscorlib.dll!System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x16 bytes
FacebookRandomizer.exe!FacebookRandomizer.App.OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) Line 86 + 0xa5 bytes C#
[Native to Managed Transition]
前三个是外部代码,第四个是我在App.xaml.cs中的方法。找到了答案,这与Facebook sdk完全无关
挂起时,我正在以pageState保存位图图像,显然这不起作用
以下是旧代码:
BitmapImage img = RandomImage.ImageSource as BitmapImage;
pageState["currentImage"] = img;
新的:
BitmapImage img = RandomImage.ImageSource as BitmapImage;
Uri uriSource = img.UriSource;
pageState["currentImage"] = uriSource;
我可以通过确保有可序列化的类型(在我的例子中是简单的viewmodel类)来解决这个问题。然后在Shared
项目中的我的App
构造函数中,确保suspendionmanager
知道我的类型。标准内置序列化程序完成了他们的工作,我也完成了
public App() {
// ... existing code ...
SuspensionManager.KnownTypes.Add(typeof(TypeOne));
SuspensionManager.KnownTypes.Add(typeof(TypeTwo));
}