简体   繁体   中英

InternetExplorer COMException: System.Runtime.InteropServices.COMexception: The RPC server is unavailable

I'm very new to C# so please excuse me if it's a silly question.

I created a console application that uses the "InternetExplorer" from SHDocVw. This application goes to a website and performs some operations. It works just fine on my computer, but when I try to publish it I just can't to get it to work on my colleagues computers. These other computers don't have dotnet core installed.

So if I publish the app as framework-dependant I get a hostfxr.dll missing library error and it obviously doesn't work at all.

I thought I could fix this by publishing the app as self-dependant. This didn't help either. I always need to paste the "Interop.MSHTML.dll" and "Interop.SHDocVw.dll" manually. When I do, the app at least starts. Internet explorer shows up, the "Navigate" command works. But as soon as I try to hide the window, or try to work with elements in the page, it just crashes.

There are two types of errors I get:

  1. Unhandled Exception: System.Runtime.InteropServices.COMexception: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) at SHDocVw.IWebBrowser2.set_Visible(Boolean pBool) at MyWebApp.IEDriver.Visibility(Boolean isVisible) at MyWebApp.Program.Main(String[] args)

  2. Other times I get a very similar error, but it's even mentions my own user files, even when running on a different machine. Is that normal?

Unhandled exception. System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. (0x800706BA) at SHDocVw.InternetExplorerClass.get_ReadyState() at IEAutomation.IEDriver.WaitForComplete() in C:\\Users\\St3ve\\source\\repos\\MyWebApp\\MyWebApp\\IEDriver.cs:line 552 at TestWeb.Program.Main(String[] args) in C:\\Users\\St3ve\\source\\repos\\MyWebApp\\MyWebApp\\Program.cs:line 82

I tried to to google the errors, but can't get it work, I would be really grateful for any hints or help.

The crux of this approach is to make sure we are accessing the right InternetExplorer object that is associated with our process

private InternetExplorer _IE; 

public Process m_Proc = Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe", "-nomerge www.google.com");

public IEDriver()
{


    Thread.Sleep(5000);
    _IE = null;
    ShellWindows m_IEFoundBrowsers = new ShellWindows();
    foreach (InternetExplorer Browser in m_IEFoundBrowsers)
    {
    if (Browser.HWND == (int)m_Proc.MainWindowHandle)
    {
    _IE = Browser;
    break;
    }
} 

Then in your methods like WaitForCompleteNew(), Navigate(), etc where ever you attempt to access InternetExplorer's proprties or methods, you can use object _IE.

_IE.Visible = false;
document = ((HTMLDocument)_IE.Document)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM