Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.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# HRESULT E_在非安全方法中失败。IWebBrowser2.Navigate2_C#_Winforms_Vsto - Fatal编程技术网

C# HRESULT E_在非安全方法中失败。IWebBrowser2.Navigate2

C# HRESULT E_在非安全方法中失败。IWebBrowser2.Navigate2,c#,winforms,vsto,C#,Winforms,Vsto,我们在Office2007内部的.NET3.5中开发了一个复杂的应用程序。在某些表单中,我们使用WebBrowser控件导航到HTML页面。问题在于,在某些计算机上,当控件调用“Navigate”方法时,会引发异常“错误HRESULT E_FAIL已从对COM组件的调用返回” 从堆栈跟踪中我们注意到,调用Navigate方法时,异常来自WebBrowser控件: in System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Navigate2

我们在Office2007内部的.NET3.5中开发了一个复杂的应用程序。在某些表单中,我们使用WebBrowser控件导航到HTML页面。问题在于,在某些计算机上,当控件调用“Navigate”方法时,会引发异常“错误HRESULT E_FAIL已从对COM组件的调用返回”

从堆栈跟踪中我们注意到,调用Navigate方法时,异常来自WebBrowser控件:

 in System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Navigate2
(Object& URL, Object& flags, Object& targetFrameName, Object& postData,
Object& headers)
  in System.Windows.Forms.WebBrowser.PerformNavigate2(Object& URL, Object&
flags, Object& targetFrameName, Object& postData, Object& headers)
  in System.Windows.Forms.WebBrowser.PerformNavigateHelper(String
urlString, Boolean newWindow, String targetFrameName, Byte[] postData,
String headers)
  in System.Windows.Forms.WebBrowser.set_Url(Uri value)
  in System.Windows.Forms.WebBrowser.set_DocumentStream(Stream value)
  in System.Windows.Forms.WebBrowser.set_DocumentText(String value)
PC是带有IE8和Office 2007 Service Pack 2的VISTA。我们使用VisualStudio2010和VSTO 3.0


非常感谢

当网页包含关闭窗口的JavaScript代码时,我观察到了这种行为

复制很简单,在WebBrowser控件中按如下方式打开HTML文件:

<html>
<head></head>
<body>
<a href="javascript:window.close();">close</a>
<!-- or a version without further user interaction -->
<a href="javascript:window.open('','_self').close();">close without request</a>
</body>
</html>

单击链接,然后将WebBrowser控件导航到另一个Url

这将导致
Navigate2
函数抛出异常
错误HRESULT E_FAIL已从对COM组件的调用返回,因为在关闭窗口时已释放了基础ActiveX组件