问题
I'm building a Windows 8 app and have come up with the following exception:
SuspensionManager failed
When running the following code:
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
await SuspensionManager.SaveAsync();
deferral.Complete();
}
The exception occurs on the third line of the method, and it doesn't really give any detail.
I've failed to find anything useful regarding this on the net. Has anyone seen this before?
//EDIT
This may be related to the fact I'm using a dynamic
type variable for the Windows 8 Facebook SDK.
Are dynamic
variables not allowed?
//EDIT 2
Here's the usage of the dynamic
variable:
dynamic result = await FB.GetTaskAsync("fql", parameters);
if (result.data.Count > 0)
{
return result.data[0].src_big as string;
}
and the call stack for the 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]
the first three are external code, and the fourth is my method in App.xaml.cs.
回答1:
Found the answer, and this is completely not Facebook-sdk related.
I was saving a Bitmap image in the pageState upon suspending, and apparently this does not work.
Here's the old code:
BitmapImage img = RandomImage.ImageSource as BitmapImage;
pageState["currentImage"] = img;
and the new one:
BitmapImage img = RandomImage.ImageSource as BitmapImage;
Uri uriSource = img.UriSource;
pageState["currentImage"] = uriSource;
回答2:
I was able to work around this by ensuring I had serializable types (in my case it was simple viewmodel classes). then in my App
constructor in the Shared
project, ensuring that the SuspensionManager
knew about my types. The standard built-in serializers did their job, and I was done.
public App() {
// ... existing code ...
SuspensionManager.KnownTypes.Add(typeof(TypeOne));
SuspensionManager.KnownTypes.Add(typeof(TypeTwo));
}
来源:https://stackoverflow.com/questions/13555722/exception-when-calling-suspensionmanager-saveasync