My program works correctly within the visual studio. Outside, displays a COM error (System.Runtime.InteropServices.COMException (0x80004005): HRESULT error E_FAIL)

Manoel Victor 1 Reputation point
2021-06-11T23:44:32.27+00:00

My program uses adobe reader dll to display pdf within a form. In visual studio the program works correctly, but when I run it out of vs 2019 it presents an error. I believe it's some missing reference.

OBS: before the project was in version 4.7.2 of .net. I've updated the entire program to 4.8. Maybe this caused some mismatch? Incompatibility that does not exist when running the program direct by vs.

PDFView_Load:

private void PDFView_Load(object sender, EventArgs e)
        {
            try
            {
                PDFViewObj.src = @"C:\Biblioteca Fácil\tempPDF.pdf"; //this file is created by other class
            }
            catch(COMException)
            {
                //Recovery options here
                Error = true;
                this.Close();
            }        
        }

This is my Exception that just occurs if executed outside the vs 2019:

System.Runtime.InteropServices.COMException (0x80004005): Erro HRESULT E_FAIL was returned from a call to the COM component.
in AcroPDFLib.IAcroAXDocShim.set_src(String pVal)
in AxAcroPDFLib.AxAcroPDF.set_src(String value)
in biblioteca.PDFView.PDFView_Load(Object sender, EventArgs e) na C:\Users\manoe\Documents\Backup de segurança\Biblioteca\biblioteca\biblioteca\PDFView.cs:linha 16
in System.Windows.Forms.Form.OnLoad(EventArgs e)
in System.Windows.Forms.Form.OnCreateControl()
in System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
in System.Windows.Forms.Control.CreateControl()
in System.Windows.Forms.Control.WmShowWindow(Message& m)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
in System.Windows.Forms.Form.WmShowWindow(Message& m)
in System.Windows.Forms.Form.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Developer technologies | .NET | .NET Runtime
Developer technologies | Visual Studio | Debugging
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Hakan Fagnell 76 Reputation points
    2021-06-12T17:07:38.007+00:00

    Run as admin? :)

    0 comments No comments

  2. Tianyu Sun-MSFT 34,441 Reputation points Microsoft External Staff
    2021-06-14T09:34:32.467+00:00

    Hello @Manoel Victor ,

    Welcome to Microsoft Q&A forum.

    Perhaps you can try to Publish your project. Right-click your project > Publish and follow the Publish wizard. You can also change some settings(add some files) of publish from right-clicking your project > Properties > Publish > (optional) Install Mode and Settings > (optional) Application Files…

    Best Regards,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.