在 Windows Phone 上启动 pdf 文件时出现 System.Runtime.InteropServices.COMException [英] System.Runtime.InteropServices.COMException when launching a pdf file on Windows Phone

查看:16
本文介绍了在 Windows Phone 上启动 pdf 文件时出现 System.Runtime.InteropServices.COMException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我之前在另一个应用程序上使用的以下工作代码打开一个 pdf 文件,

I am trying to open a pdf file using the below working code I previously used on another app,

但是这一次当流到达这一行时我得到 System.Runtime.InteropServices.COMException:Windows.System.Launcher.LaunchFileAsync(pdffile);

but this time I am getting System.Runtime.InteropServices.COMException when the flow hits this line: Windows.System.Launcher.LaunchFileAsync(pdffile);

这个异常的含义是什么以及如何摆脱它?

What is the meaning of this exception and how to get rid of it?

请注意,无需关心此异常(禁用它),

Please note that without caring about this exception (disabling it),

文件仍然无法打开.

请注意:该文件存在于我的隔离文件夹中(使用 wpowertool 检查),

Please note: the file exists in my isolated folder (checked with wpowertool),

我尝试了 2 个不同的文件,所以这不应该是文件损坏的问题.

I tried with 2 different files so it shouldnt be a matter of file corruption.

    public void openFile(string options)
    {
        System.Diagnostics.Debug.WriteLine("options: " + options);
        string optVal = JsonHelper.Deserialize<string[]>(options)[0];
        asyncOpen(optVal);
    }

    public async Task asyncOpen(string filename)
    {
            filename = filename.Substring(2, filename.Length - 2);
            filename = filename.Replace("//", "/").Replace("/", "\\");
            Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
            Debug.WriteLine("local: " + local.Path);
            Windows.Storage.StorageFile pdffile = await local.GetFileAsync(filename);
            Debug.WriteLine("pdffile: " + pdffile.Name);
            //// Launch the pdf file.
                Windows.System.Launcher.LaunchFileAsync(pdffile); 
    }

这个 MSDN 帖子 属于我.是的,文件已安装,我有 acrobat 阅读器.

this MSDN post belongs to me. Yes, the file is installed and I have acrobat reader.

请注意,此 C# 代码是一个 phonegap/cordova 插件在我的混合应用程序中通过 javascript 调用.

Please note that this C# code is a phonegap/cordova plugin which is called via javascript in my hybrid application.

推荐答案

注意本MSDN 文章 - Launcher.LaunchFileAsync(IStorageFile):

调用 API 时,调用应用程序必须对用户可见.
必须从 ASTA 线程(也称为 UI线程).

The calling app must be visible to the user when the API is invoked.
This API must be called from an ASTA thread (also known as a UI thread).

<小时>非常感谢 OP 分享解决方案.以下代码应该可以帮助其他人解决这个问题:


Huge ups to the OP for sharing the solution. The following code should help others get around this issue:

Deployment.Current.Dispatcher.BeginInvoke(() => { asyncOpenFile(options); }); 

这篇关于在 Windows Phone 上启动 pdf 文件时出现 System.Runtime.InteropServices.COMException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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