Skip to content

An unhandled exception was thrown by the 'Execute' method #7591

@klaudia-glowacka

Description

@klaudia-glowacka

Describe the bug

When running UI tests with MSTest in a .NET 9 project, the test initialization fails with the following error:
TestMethod 2 An unhandled exception was thrown by the 'Execute' method. Please report this error to the author of the attribute 'Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute'. System.InvalidOperationException: UITestMethodAttribute.DispatcherQueue should not be null. To use UITestMethodAttribute within a WinUI Desktop App, remember to set the static UITestMethodAttribute.DispatcherQueue during the test initialization. at Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.ExecuteAsync(ITestMethod testMethod) in //src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:line 48 at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.<>c__DisplayClass11_0.<b__0>d.MoveNext() in //src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs:line 409 --- End of stack trace from previous location --- at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.ExecuteTestAsync(TestMethodInfo testMethodInfo) in /_/src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs:line 418

Version used

MSTest" Version="4.1.0"
MSTest.TestAdapter" Version="4.1.0"
MSTest.TestFramework" Version="4.1.0"
Microsoft.TestPlatform.TestHost" Version="18.3.0" />
Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.7705"
Microsoft.WindowsAppSDK" Version="1.8.260209005"

Steps To Reproduce

  1. Create a UI test project targeting .NET 9 using MSTest.
  2. Run the tests using Visual Studio or the command line.
  3. Observe that it throws an exception.

Expected behavior

The test app should launch, and UITestMethodAttribute.DispatcherQueue should be initialized before tests run, allowing UI tests to execute.

Actual behavior

The test app does not appear to launch or initialize the dispatcher queue, causing the initialization to fail and all tests to abort.

Additional context

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions