单元测试项目中的WebBrowser COMException [英] WebBrowser COMException in Unit Test project
问题描述
我正在尝试创建一个包含WebBrowser控件的单元测试.尝试做一些简单的事情,例如实例化WebBrowser并调用Navigate()方法会引发以下COMException(HResult = -2147467259):
I'm attempting to create a unit test that includes a WebBrowser control. Trying to do something as simple as instantiating a WebBrowser and calling the Navigate() method raises the following COMException (HResult = -2147467259):
UnitTest1.TestMethod1引发了异常:
System.Runtime.InteropServices.COMException:错误HRESULT E_FAIL已从对COM组件的调用返回.
结果堆栈跟踪:
,位于System.Windows.Forms.UnsafeNativeMethods.IWebBrowser2.Navigate2(对象和URL,对象和标志,对象和targetFrameName,对象和postData,对象和标头)
,位于System.Windows.Forms.WebBrowser.PerformNavigate2(对象和URL,对象和标志,对象和targetFrameName,对象和postData,对象和标头)
在System.Windows.Forms.WebBrowser.Navigate(String urlString)
我已经验证(通过附加到测试可执行文件)单元测试方法正在STA线程上运行,但这似乎无关紧要.
I've verified (by attaching to the test executable) that the unit test method is running on an STA thread but it doesn't seem to matter.
以下是产生问题的简单步骤:
Here's the simple steps to produce the problem:
1.在VS 2012中创建一个单元测试项目.
1. Create a Unit Test project in VS 2012.
2.添加对System.Windows.Forms的引用,以便能够使用WebBrowser控件.
2. Add a reference to System.Windows.Forms to be able to use the WebBrowser control.
3. 使用以下代码作为您的测试方法:
3. Use the following code for your test method:
[TestMethod]
[STAThread()]
public void TestMethod1()
{
var browser = new System.Windows.Forms.WebBrowser();
browser.Navigate("about:blank");
}
MCPD
MCPD
推荐答案
我正在尝试让熟悉此主题的人参与进来这个问题.可能会有一些时间延迟.感谢您的耐心.
最好的问候
这篇关于单元测试项目中的WebBrowser COMException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!