Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IE和插件的奇怪行为(.Net-based)_C#_Internet Explorer_Plugins - Fatal编程技术网

C# IE和插件的奇怪行为(.Net-based)

C# IE和插件的奇怪行为(.Net-based),c#,internet-explorer,plugins,C#,Internet Explorer,Plugins,我正在使用SpicIE框架和C#4.0为Internet Explorer编写一个插件。我的插件执行以下操作:用户按下按钮(共享链接按钮),插件打开带有特定url的独立IE窗口。 当我执行以下操作时:打开3个选项卡,从最后一个到第一个单击“共享链接”,->tabs#3和#2正常打开窗口。选项卡1引发异常: System.Runtime.InteropServices.COMException(0x80004005):调用COM组件时返回错误HRESULT E_FAIL。 在SHDocVw.IWe

我正在使用SpicIE框架和C#4.0为Internet Explorer编写一个插件。我的插件执行以下操作:用户按下按钮(共享链接按钮),插件打开带有特定url的独立IE窗口。 当我执行以下操作时:打开3个选项卡,从最后一个到第一个单击“共享链接”,->tabs#3和#2正常打开窗口。选项卡1引发异常:

System.Runtime.InteropServices.COMException(0x80004005):调用COM组件时返回错误HRESULT E_FAIL。 在SHDocVw.IWebBrowser2.get_Document()上 在BGPlugin.Entities.Bookmarklet.ExecuteLinkShareWindow()处 在BGPlugin.UserControls.LinkShareControl.btnAdd_点击(对象发送者,事件参数e) 在System.Windows.Forms.Control.OnClick(EventArgs e)中 在System.Windows.Forms.Button.OnClick(EventArgs e)中 在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs-mevent)上 在System.Windows.Forms.Control.WmMouseUp(Message&m、MouseButtons按钮、Int32单击) 位于System.Windows.Forms.Control.WndProc(Message&m) 位于System.Windows.Forms.ButtonBase.WndProc(Message&m) 在System.Windows.Forms.Button.WndProc(Message&m)中 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)中 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)中 在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam)中

在调试过程中,我还从Visual Studio 2010中获得了以下异常,就在上述异常之前:

检测到断开连接的上下文。 上下文0x2fb4b0已断开连接。不会使用代理为COM组件上的请求提供服务。这可能会导致损坏或数据丢失。为了避免此问题,请确保所有上下文/单元都保持活动状态,直到应用程序完全使用RuntimeCallableWrappers完成,RuntimeCallableWrappers表示位于它们内部的COM组件

我注意到了一件非常神秘的事情:只有在以下情况下才有例外:

失败选项卡的已打开选项卡数索引(基于1,0表示无)

--------3-----------------1

--------4-----------------0

--------5-----------------2

--------6-----------------3

--------7-----------------0

--------8-----------------5

--------9-----------------8

--------10-----------------0

--------11------------------0

--------12------------------4

我使用以下代码打开新窗口:

Plugin.HostInstance.NewWindow(uri,windowName)

NewWindow(…)方法在引擎盖下使用以下代码:

 try
        {
            object URL = url;
            object flags = System.Reflection.Missing.Value; //special "nothing" value
            object targetName = System.Reflection.Missing.Value; //special "nothing" value
            object postData = System.Reflection.Missing.Value; //special "nothing" value
            object headers = System.Reflection.Missing.Value; //special "nothing" value

            InternetExplorer ie = (InternetExplorer)new InternetExplorer();
            ie.AddressBar = false;
            ie.ToolBar = 0;
            ie.StatusBar = false;
            ie.Width = 480;
            ie.Height = 480;
            ie.Resizable = false;

            ie.Navigate2(ref URL, ref flags, ref targetName, ref postData, ref headers);
            ie.Visible = true;
        }
        catch (Exception ex)
        {
            TraceSink.TraceEvent(TraceEventType.Error, 0, "Exception in Host.NewWindow :" + ex);
        }
我尝试使用以下代码代替NewWindow:

var psi = new ProcessStartInfo("iexplore", uri);
Process p = new Process();
p.StartInfo = psi;
p.Start();  
错误现在不是经常发生,而是不时发生


请帮助我修复或克服此错误。

IE中的每个选项卡都在自己的线程上打开,具有自己的BHO/工具栏实例等。在自己的进程中每启动3个或更多选项卡。因此,只使用一个静态Plugin.HostInstance是完全错误的。
我的第一个解决方法是使用静态字典,该字典在DocumentComplete上填写,但在访问浏览器文档属性时,我经常收到UnauthorizedAccessException,因此,我认为正确的模式是使用IObjectWithSite COM接口中的GetSite方法。

在此之前请注意:正如SpicIE主页上所述,出于性能和稳定性原因,不鼓励使用.NET技术扩展IE。