Throw PlatformNotSupportedException in STATestMethodAttribute on non-Windows#7862
Merged
Evangelink merged 4 commits intomainfrom Apr 27, 2026
Merged
Throw PlatformNotSupportedException in STATestMethodAttribute on non-Windows#7862Evangelink merged 4 commits intomainfrom
Evangelink merged 4 commits intomainfrom
Conversation
STA (Single Threaded Apartment) is a Windows-only COM threading concept. On non-Windows platforms, STATestMethodAttribute now: - Runs the test without STA context (unchanged behaviour) - Appends a warning to the test output explaining STA was not applied - Documents the design decision with a clear code comment Removes the ambiguous '// TODO: Throw?' comment.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR clarifies and formalizes the behavior of STATestMethodAttribute on non-Windows platforms by documenting the design decision and emitting a localized warning in test output when STA cannot be applied.
Changes:
- Updated
STATestMethodAttribute.ExecuteAsyncto keep running tests on non-Windows, and append a warning toTestResult.LogOutput. - Added a new localized resource string
STATestMethodNonWindowsWarning. - Updated the generated localization
.xlffiles to include the new resource entry.
Show a summary per file
| File | Description |
|---|---|
| src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs | Adds documented non-Windows behavior and appends a warning message to each returned TestResult. |
| src/TestFramework/TestFramework/Resources/FrameworkMessages.resx | Introduces the new STATestMethodNonWindowsWarning resource string. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf | Adds the new trans-unit for localization. |
| src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf | Adds the new trans-unit for localization. |
Copilot's findings
- Files reviewed: 15/15 changed files
- Comments generated: 2
Member
Author
|
Sorry I asked to create PR in the wrong chat... will do the changes I wanted here |
STATestMethodAttribute now throws PlatformNotSupportedException on non-Windows platforms since STA is a Windows-only COM concept. The error message guides users to use [OSCondition(OperatingSystems.Windows)] to skip the test on non-Windows platforms.
Add NETFRAMEWORK-compatible OS check using Environment.OSVersion.Platform so that STATestMethodAttribute throws PlatformNotSupportedException on Mono running on non-Windows, not just on .NET Core/5+.
Youssef1313
reviewed
Apr 27, 2026
Member
Author
|
@copilot please revert last commit |
Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/8c15cc9b-8fd9-4ff5-8b6a-4465ba920aac Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Contributor
Member
Author
|
@Youssef1313 PR is ready |
nohwnd
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
STATestMethodAttribute.ExecuteAsynchad an ambiguous// TODO: Throw?comment on the non-Windows code path (line 79). The test would silently run without STA context on non-Windows, with no indication to the user.Change
Replace the
// TODO: Throw?with aPlatformNotSupportedException. STA (Single Threaded Apartment) is a Windows-only COM threading concept — silently running without it is misleading. Failing explicitly makes the contract clear.The error message guides users to use
[OSCondition(OperatingSystems.Windows)]to skip the test on non-Windows platforms.Changes
STATestMethodAttribute.cs: ThrowPlatformNotSupportedExceptionon non-Windows instead of silently executing without STA.FrameworkMessages.resx: AddedSTATestMethodNonWindowsNotSupportedresource string.xlf/files: Auto-generated by build.