调用SuspensionManager.SaveAsync()时出现exception

我正在构建一个Windows 8应用程序,并提出以下exception:

SuspensionManager失败

运行以下代码时:

private async void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); await SuspensionManager.SaveAsync(); deferral.Complete(); } 

exception发生在方法的第三行,并没有真正给出任何细节。

我没有在网上找到任何有用的信息。 谁看过这个吗?

//编辑

这可能与我使用Windows 8 Facebook SDK的dynamic类型变量有关。

是不允许dynamic变量?

//编辑2

这是dynamic变量的用法:

 dynamic result = await FB.GetTaskAsync("fql", parameters); if (result.data.Count > 0) { return result.data[0].src_big as string; } 

以及exception的调用堆栈:

 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中保存了一个Bitmap图像,显然这不起作用。

这是旧代码:

 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构造函数中,确保SuspensionManager知道我的类型。 标准的内置序列化器完成了他们的工作,我完成了。

  public App() { // ... existing code ... SuspensionManager.KnownTypes.Add(typeof(TypeOne)); SuspensionManager.KnownTypes.Add(typeof(TypeTwo)); }