我正在爲使用SpicIE框架和C#4.0的Internet Explorer編寫一個插件。我的插件執行以下操作:用戶按下按鈕(共享鏈接按鈕),插件打開單獨的IE窗口與特定的URL。 當我做到以下幾點:打開3個選項卡,從最後到第一次點擊'共享鏈接', - >標籤#3和#2打開窗口正常。 Tab#1拋出異常:IE和插件的奇怪行爲(基於.Net)
System.Runtime.InteropServices.COMException(0x80004005):錯誤HRESULT E_FAIL已從調用返回到COM組件。 在SHDocVw.IWebBrowser2.get_Document() 在BGPlugin.Entities.Bookmarklet.ExecuteLinkShareWindow() 在BGPlugin.UserControls.LinkShareControl.btnAdd_Click(對象發件人,EventArgs的) 在System.Windows.Forms.Control.OnClick(EventArgs的) 在System.Windows.Forms.Button.OnClick(EventArgs的) 在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 在System.Windows.Forms.Control.WmMouseUp(消息&米,MouseButtons按鈕INT32點擊) 在System.Windows.Forms.Control.WndProc(消息&米) 在System.Windows.Forms.ButtonBase.WndProc(消息&米) 在System.Windows.Forms.Button.WndProc(在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息&米) 在System.Windows.Forms.NativeWindow消息&米) 。回調(IntPtr的的HWND,味精的Int32,IntPtr的WPARAM,LPARAM的IntPtr)
此外,在調試我越來越從Visual Studio 2010以下異常前夕上述異常:檢測
斷開連接上下文。 上下文0x2fb4b0已斷開連接。將不使用代理服務於COM組件上的請求。這可能會導致損壞或數據丟失。爲避免此問題,請確保所有上下文/公寓都保持活動狀態,直到應用程序完全使用表示其內部的COM組件的RuntimeCallableWrappers完成爲止。
我注意到一個很玄的東西:只有在下列情況下,上述occers例外:
開數失敗的選項卡的標籤指數(從1,0表示沒有)
-------- 3 ----------------------- 1
-------- 4 --- -------------------- 0
-------- 5 ---------------- ------- 2
-------- 6 ----------------------- 3
-------- 7- ---------------------- 0
-------- 8 -------------- --------- 5
-------- 9 ----------------------- 8
-------- 10 ---------------------- 0
-------- 11 ---- ------------------ 0
- ------- 12 ---------------------- 4
我用下面的代碼以打開新的窗口:
插件.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();
錯誤發生,現在不regulary但時不時。
請幫我解決或克服這個錯誤。
請仔細閱讀本文,以備不時之需:正如SpicIE主頁上所述,使用.NET技術來擴展IE是出於性能和穩定性原因而不鼓勵的。 – EricLaw 2011-05-13 15:57:38