gpt4 book ai didi

c# - 如何修复错误 : "The currentthread needs to have its apartmentstate set to ApartmentState.sta to be able to initiate Internet Explorer"?

转载 作者:太空狗 更新时间:2023-10-29 20:56:58 26 4
gpt4 key购买 nike

我在 C# 中有以下代码:

namespace Tests
{
[SetUpFixture, RequiresSTA]
public class Setup
{
public IE Window = new IE("webpage");

[SetUp]
public void SetUp()
{

}

[TearDown]
public void TearDown()
{

}
}
}

当我尝试在我的网站上运行它时,它返回错误:

"The currentthread needs to have its apartmentstate set to ApartmentState.sta to be able to initiate Internet Explorer"

通常在使用除 SetupFixture 之外的任何东西时,RequiresSTA 都是解决方案。但由于某种原因,它现在不起作用。

最佳答案

如果包含以下行,解决方案最终变得相当简单:

[assembly: RequiresSTA] 

在页面顶部,它将设置整个程序集以使用 STA,并且不再抛出错误。

关于c# - 如何修复错误 : "The currentthread needs to have its apartmentstate set to ApartmentState.sta to be able to initiate Internet Explorer"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12753720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com