Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda