瓦廷和 ApartmentState.STA
问题:“CurrentThread 需要将其 ApartmentState 设置为 ApartmentState.STA 才能自动化 Internet Explorer。”
首先,我已经阅读了上述问题的所有解决方案,但没有一个对我有用。可能是我遗漏了一些东西。我尝试将执行线程条目添加到我的 app.config 中,还尝试设置 STAThread 属性,但我仍然面临与上述相同的异常。
工具:Visual Studio 2010、Watin 2.1、c#
场景:尝试在单击按钮时从 Web 应用程序运行单元测试 [c# 中的 watin 脚本]。但是当脚本即将在以下行启动 IE 时,会引发上述异常: IE mybrowser = new IE("SomeURL here");
有什么想法吗?
Issue: "The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer."
First of all i have read all the solutions to the problems above and none works for me.May be i am missing something. I have tried adding Execution Thread entry into my app.config, also tried setting STAThread attribute and i am still facing the same exception as stated above.
Tools: Visual Studio 2010, Watin 2.1, c#
Scenario: Trying to run a unit test [watin script in c#] from a web application upon a button click. But the above exception is thrown when the script is about to launch IE on the following line :
IE mybrowser = new IE ("SomeURL here");
Any Thoughts ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从朋友那里得到的。我们实际上不必添加任何 app.config 条目。只需在单一状态下启动线程即可。就我而言,我在按钮单击处理程序中编写了以下代码:
Got it from a friend. We actually dont have to add any app.config entry. Just start the thread in a single state. In my case, i wrote the following code in my button click handler:
您的 App.Config 是什么样的?
以上适用于我的Win7、IE9(32位)和Watin2.1。它还适用于 WinXP、IE8、WatiN 2.1。我 99% 确信它在以前版本的 WatiN 上也能正常工作。不需要进行其他 ApartmentState 更改。
What does your App.Config look like?
The above works for me on Win7, IE9 (32bit), and Watin2.1. It also works on WinXP, IE8, WatiN 2.1. I'm 99% sure it worked just fine on previous versions of WatiN as well. No other ApartmentState changes were needed.
只需在文件顶部或项目的入口点添加 [ assembly: RequiresSTA] 即可。
Simply add [assembly: RequiresSTA] at the top of your file or at the entry point of your project.
我已经完成了 app.config 更改,
但没有骰子。我打开 AssemblyInfo 并添加
,突然间,宇宙开始再次正常运行。
I had already done the app.config changes
but no dice. I opened AssemblyInfo and added
and suddenly, the universe began to function properly again.