System.Runtime.InteropServices.COMException而导致终止应用程序 [英] System.Runtime.InteropServices.COMException caused while terminating the app

查看:1640
本文介绍了System.Runtime.InteropServices.COMException而导致终止应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2页的应用程序calendar.xaml(开始页)和historystatistics.xaml。当我浏览到historystatistics和回历,然后尝试通过下拉手势终止应用程序引发错误。在App.xaml中的OnSuspending的SaveAsync功能时,会出现提到的错误。

 专用异步无效OnSuspending(对象发件人,SuspendingEventArgs E) 
{
CycleManager cycMan = CycleManager.Instance;
VAR延期= e.SuspendingOperation.GetDeferral();
// TODO:保存应用程序状态并停止任何后台活动
如果(cycMan.Reset =真!)
{
等待Appname.Common.SuspensionManager.SaveAsync(); // **错误**
}
deferral.Complete();
}



报告说,



<块引用>

类型的'System.Runtime.InteropServices.COMException'
异常出现在mscorlib.dll,但在用户代码中没有处理。



GetNavigationState不支持被传递给Frame.Navigate参数类型
的序列化。




在哪里做我错了吗?我做了一个简单的导航从historystatistics页从这样

 < XAML按钮X:NAME =后退按钮点击=GoBack的IsEnabled ={结合Frame.CanGoBack,的ElementName = pageRoot}风格={StaticResource的BackButtonStyle}/> 


解决方案

的问题是,SuspensionManager使用Frame.GetNavigationState()以获得帧的历史。然后它试图序列化导航历史记录为一个字符串,遗憾的是它没有办法知道如何序列化的自定义复杂类型



从的 MSDN




请注意这些方法中使用的序列化格式是内部
仅使用。您的应用程序不应成为它的任何依赖关系。
此外,这种格式只支持基本类型
类似的字符串,字符,数字和GUID类型的系列化。




对于这个问题重写NavigationParameter或者如果你不想保存您的应用程序的状态只是注释行最好的解决办法:

 专用异步无效OnSuspending(对象发件人,SuspendingEventArgs E)
{
VAR延期= e.SuspendingOperation.GetDeferral();
//等待SuspensionManager.SaveAsync();
deferral.Complete();
}


I have an app with 2 pages calendar.xaml(start page) and historystatistics.xaml. Error is thrown when I navigate to historystatistics and back to calendar and then try to terminate the app by the pulling down gesture. The mentioned error occurs at the SaveAsync function in OnSuspending of App.xaml.

    private async void OnSuspending(object sender, SuspendingEventArgs e)
    {
        CycleManager cycMan = CycleManager.Instance;
        var deferral = e.SuspendingOperation.GetDeferral();
        //TODO: Save application state and stop any background activity
        if (cycMan.Reset != true)
        {
            await Appname.Common.SuspensionManager.SaveAsync(); // **ERROR**
        }
        deferral.Complete();          
    }

It says

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code.

GetNavigationState doesn't support serialization of a parameter type which was passed to Frame.Navigate.

Where did I wrong? I did a simple navigation from historystatistics page from xaml like this

<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>

解决方案

The problem is that SuspensionManager uses Frame.GetNavigationState() to get the history of the Frame. It then tries to serialize the navigation history to a string, unfortunately it has no way to know how to serialize custom complex types .

From MSDN :

Note The serialization format used by these methods is for internal use only. Your app should not form any dependencies on it. Additionally, this format supports serialization only for basic types like string, char, numeric and GUID types.

The best solution for this problem to rewrite the NavigationParameter or if you didn't want to save your app state just comment the line :

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

这篇关于System.Runtime.InteropServices.COMException而导致终止应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆