Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
System.Runtime.InteropServices.COMException when launching a pdf file on Windows Phone

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

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),

the file still cannot be opened.

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

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); 
    }

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

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

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Pay attention to the remarks in this MSDN Article - Launcher.LaunchFileAsync(IStorageFile):

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).


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); }); 
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda