【问题标题】:Exception when calling SuspensionManager.SaveAsync()调用 SuspensionManager.SaveAsync() 时出现异常
【发布时间】:2014-08-25 13:07:14
【问题描述】:

我正在构建一个 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 使用 dynamic 类型变量有关。

是否不允许使用 dynamic 变量?

//编辑2

这是dynamic变量的用法:

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中的方法

【问题讨论】:

    标签: c# exception windows-8 facebook-c#-sdk


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-06
        • 2017-10-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多