question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[3.0 regression] Unable to run a test with timeout in STA ApartmentState

See original GitHub issue

Describe the bug

MSTest v2 ran all tests in STA ApartmentState when executed in a .NET Framework runtime. v3 runs “normal” tests still in STA, but tests that have a TimeoutAttribute applied now run in MTA.

Steps To Reproduce

Run these tests with various versions of MSTest and runtimes:

[TestMethod]
public void TestMethod1()
{
    // Outputs:
    // MSTest   net7.0   net48
    // 2.2.10   MTA      STA
    // 3.0.2    MTA      STA
    Console.WriteLine(Thread.CurrentThread.GetApartmentState());
}

[TestMethod, Timeout(1000)]
public void TestMethod2()
{
    // Outputs:
    // MSTest   net7.0   net48
    // 2.2.10   MTA      STA
    // 3.0.2    MTA      MTA    <-- Problem
    Console.WriteLine(Thread.CurrentThread.GetApartmentState());
}

Expected behavior

Either MSTest v2 behavior should be retained, or I should have a way to force STA on an unit test.

Actual behavior

Tests with timeout always run in MTA.

Additional context

I need STA to run UI (WPF) tests. Those tests try to execute WPF commands which now fail with InvalidOperationException: The calling thread must be STA, because many UI components require this.

This is most likely a side effect of #1296 The package “MSTest.STAExtensions” which is mentioned in #21 does not help/work, see saikrishnav/testfxSTAext#5 Related: #320

AB#1822144

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Reactions:1
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Evangelinkcommented, May 19, 2023

@cremor we have reverted the change and will include the fix in 3.0.3 (we hope to ship it next week).

@fforjan I believe this revert won’t be enough for you as you would want to run some tests with STA using .NET 6 and this won’t be possible (it was not possible in previous versions of MSTest). I have created #1674 to track providing a good solution for this use case.

1reaction
Evangelinkcommented, May 15, 2023
Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with runnig NUnit tests under STA
This works fine if I run my unit test on NUnit console or on NUnit GUI without using a NUnit project file. However,...
Read more >
Framework Release
For the NUnit3TestAdapter, you will need version 4.5 to run tests with NUnit 4. ... framework like setting the ApartmentState and enabling Timeout...
Read more >
Timeouts:Issues and Resolutions
1. Idle Timeout​. If the LambdaTest Selenium grid detects inactivity for 120 seconds then you may encounter the below error: · 2. Improper...
Read more >
https://raw.githubusercontent.com/dotnet/samples/m...
Failing tests : build /p=IncludeTraits=ActiveIssue=17 20 area-System.Xml 2 XPath.XDocument tests fail because of lacking feature "XPath.
Read more >
Visual studio performance testing quick reference guide pdf
show up properly 91 Socket errors or “Service Unavailable” errors when running a load test 92 Error “Failed to load results from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found