question

ManoelVictor-6091 avatar image
0 Votes"
ManoelVictor-6091 asked TianyuSun-MSFT commented

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

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)

dotnet-csharpdotnet-runtimevs-debugging
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe the path that is assigned to src is not valid? Show some details about PDFView_Load.

0 Votes 0 ·

the path is valid. Before calling the PDFView a tempPDF file.pdf is generated with what will be displayed.
the same path works when the program is running by the visual studio. But it didn't work if I run the .exe file without Visual Studio, i.e. directly through the output directory

 private void PDFView_Load(object sender, EventArgs e)
             {
                 try
                 {
                     PDFViewObj.src = @"C:\Biblioteca Fácil\tempPDF.pdf"; //this file is generated by a class of pdf
                 }
                 catch(COMException)
                 {
                     //Operations of Exception as backup and recovery here
                     this.Close();
                 }        
             }


0 Votes 0 ·

Maybe the path is valid, but the content is not valid for some reasons. Did you try to open this file manually when the program stops?

If possible, you can try to recompile and recheck the program using previous version of .NET Framework.



0 Votes 0 ·
Show more comments
HakanFagnell avatar image
0 Votes"
HakanFagnell answered

Run as admin? :)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TianyuSun-MSFT avatar image
0 Votes"
TianyuSun-MSFT answered

Hello @ManoelVictor-6091 ,

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.