UnsafeNativeMethods.IWebBrowser2.Navigate2 中的 HRESULT E_FAIL [英] HRESULT E_FAIL in UnsafeNativeMethods.IWebBrowser2.Navigate2

查看:39
本文介绍了UnsafeNativeMethods.IWebBrowser2.Navigate2 中的 HRESULT E_FAIL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 Office 2007 中使用 .NET 3.5 开发了一个复杂的应用程序.在某些表单中,我们使用 WebBrowser 控件导航到我们的 HTML 页面.问题是在某些机器上,当控件调用导航"方法时,它会引发异常错误 HRESULT E_FAIL 已从对 COM 组件的调用返回".

We developed a complex application in .NET 3.5 inside Office 2007. In some Forms we use the WebBrowser control to navigate to our HTML pages. The problem is that on some machines when the control invoke the "Navigate" method it raises an exception "error HRESULT E_FAIL has been returned from a call to a COM component".

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

From the stack trace we note that the exception come from the WebBrowser control when invoking the Navigate method:

 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.我们使用 Visual Studio 2010 和 VSTO 3.0.

PCs are VISTA with IE8 and Office 2007 Service Pack 2. We use Visual Studio 2010 and VSTO 3.0.

非常感谢

推荐答案

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

I have observed this behaviour when Webpages include JavaScript code that closes the window.

重现很简单,在您的 WebBrowser 控件中打开一个如下所示的 HTML 文件:

It's simple to reproduce, open an HTML file like the following in your WebBrowser Control:

<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 Control 导航到另一个 Url.

Click on the link and afterwards navigate your WebBrowser Control to another Url.

这将导致 Navigate2 函数抛出异常 error HRESULT E_FAIL has been returned from a call to a COM component,因为底层 ActiveX 组件在关闭时被释放窗户.

This will cause the Navigate2 function to throw the Exception error HRESULT E_FAIL has been returned from a call to a COM component, because the underlying ActiveX component was disposed when closing the window.

这篇关于UnsafeNativeMethods.IWebBrowser2.Navigate2 中的 HRESULT E_FAIL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆