调用SuspensionManager.SaveAsync()时出现异常。

5

我正在开发一款Windows 8应用程序,但遇到了以下异常:

SuspensionManager 失败

该异常出现在运行以下代码时:

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

该异常发生在该方法的第三行,并没有提供任何详细信息。
我在网上未能找到任何有用的内容。有人遇到过这种情况吗?
//编辑
这可能与我在Windows 8 Facebook SDK中使用动态类型变量有关。
动态变量不被允许吗?
//编辑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中的方法。

2个回答

2

我找到了答案,这与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;

1

我通过确保我有可序列化的类型(在我的情况下,它是简单的视图模型类)来解决了这个问题。然后在Shared项目中的App构造函数中,确保SuspensionManager知道我的类型。标准内置的序列化程序完成了它们的工作,问题得以解决。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接