在某些 2008 R2 环境中使用 WebBrowser 控件出现 COMException
在某些 2008 R2 环境(而不是其他环境)中,我在使用 System.Windows.Forms.WebBrowser
控件时收到 COMExceptions
。无论是通过 DocumentText
属性指定内容还是使用 URL 参数调用 Navigate
方法,我都会遇到相同的异常:
COMException - Error HRESULT E_FAIL has returned from a调用 COM 组件。
在 System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Refresh()
我发现设置在指定 DocumentText
之前,WebBrowser
上的 ScrollBarsEnabled
属性会导致此异常,并且这似乎是由于调用 Refresh此处)。解决此问题的方法是设置一些模拟内容并调用
Application.DoEvents()
。但即使这样做了,它也会在稍后加载内容时(在另一个线程中完成)导致上述异常。
请注意,我指定的 DocumentCompleted
委托正在被命中,但其 WebBrowser.axIWebBrowser2.StatusText
显示发生了异常,并且 WebBrowser.Document
为空。
我可以建立一个简单的应用程序来重现该问题,但我必须找到一个可以重现该错误的 2008 R2 实例才能进行调试。我更多地询问是否有人知道可能影响或导致问题的原因,可能与 COM 安全性等有关。
请注意,我正在 STA Apartment
中执行 WebBrowser
代码>状态。
任何想法或建议将不胜感激。提前致谢! -最大限度
In certain 2008 R2 environments and not others, I'm getting a COMExceptions
when utilizing a System.Windows.Forms.WebBrowser
control. Whether specifying contents via the DocumentText
property or invoking the Navigate
method with a URL parameter, I get the same exception:
COMException - Error HRESULT E_FAIL has been returned from a call to a COM component.
at System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Refresh()
I've found that setting the ScrollBarsEnabled
property on the WebBrowser
before specifying DocumentText
causes this exception, and that appears to be as a result of calling the Refresh
method (referenced above) when the browser has no contents (Last post here). A workaround for this is to set some mock contents and calling Application.DoEvents()
. But even with this in place, it causes the above exception while loading the contents later on (done in another thread).
Note that the DocumentCompleted
delegate I specify is being hit, but its WebBrowser.axIWebBrowser2.StatusText
shows that the exception has occurred, and the WebBrowser.Document
is empty.
I could put up a simple app to repro the issue, but I'd have to find a 2008 R2 instance where the bug is reproducible in order to debug. I'm more asking if anyone has ideas of what might be affecting or causing the issue, perhaps with relation to COM security etc.
Note that I am executing the WebBrowser
in a STA Apartment
state.
Any ideas or suggestions would be greatly appreciated. Thanks in advance!
-Max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论