From 5d84a207260a5b2678ca76242f5ea6b8dbe41eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 27 Apr 2026 12:09:26 +0200 Subject: [PATCH 1/4] Document STATestMethodAttribute non-Windows behaviour and add warning 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. --- .../TestMethod/STATestMethodAttribute.cs | 18 ++++++++++++++++-- .../Resources/FrameworkMessages.resx | 4 ++++ .../Resources/xlf/FrameworkMessages.cs.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.de.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.es.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.fr.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.it.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.ja.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.ko.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.pl.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.ru.xlf | 5 +++++ .../Resources/xlf/FrameworkMessages.tr.xlf | 5 +++++ .../xlf/FrameworkMessages.zh-Hans.xlf | 5 +++++ .../xlf/FrameworkMessages.zh-Hant.xlf | 5 +++++ 15 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs index dd423b5248..a9a0682ab2 100644 --- a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs @@ -76,8 +76,22 @@ public override async Task ExecuteAsync(ITestMethod testMethod) #if !NETFRAMEWORK if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - // TODO: Throw? - return await ExecuteCoreAsync(testMethod).ConfigureAwait(false); + // STA (Single Threaded Apartment) is a Windows-only COM threading concept and is not + // supported on non-Windows platforms. The test is executed on the current thread without + // STA context, which is acceptable because STA has no meaning outside of Windows. + TestResult[] nonWindowsResults = await ExecuteCoreAsync(testMethod).ConfigureAwait(false); + string warning = string.Format( + CultureInfo.InvariantCulture, + FrameworkMessages.STATestMethodNonWindowsWarning, + testMethod.TestMethodName); + foreach (TestResult result in nonWindowsResults) + { + result.LogOutput = result.LogOutput is null + ? warning + : result.LogOutput + Environment.NewLine + warning; + } + + return nonWindowsResults; } #endif diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index ee8056bb41..c7ac505a54 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -405,4 +405,8 @@ Actual: {2} Nested assert scopes are not allowed. Dispose the current scope before creating a new one. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 4ba65efbe5..537794ddb0 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -358,6 +358,11 @@ Skutečnost: {2} Elementy <{0}> se v kolekci nenachází. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} Řetězec „{0}“ nezačíná řetězcem „{1}“. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index 68c705ab3c..98c786c057 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -358,6 +358,11 @@ Tatsächlich: {2} Element(e) <{0}> ist/sind in der Auflistung nicht vorhanden. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} Die Zeichenfolge „{0}“ beginnt nicht mit der Zeichenfolge „{1}“. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 09f2d652ff..428a100452 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -358,6 +358,11 @@ Real: {2} Los elementos <{0}> no están presentes en la colección. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} La cadena "{0}" no empieza con la cadena "{1}". {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index 141e1fb731..f669095e6b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -358,6 +358,11 @@ Réel : {2} L’élément ou les éléments <{0}> n’est ou ne sont pas présent(s) dans la collection. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} La chaîne '{0}' ne commence pas par la chaîne '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index e2b3fada9c..14242cbdd2 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -358,6 +358,11 @@ Effettivo: {2} Gli elementi <{0}> non sono presenti nella raccolta. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} La stringa '{0}' non inizia con la stringa '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 7edf1c0606..93e57a6e14 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -358,6 +358,11 @@ Actual: {2} 要素 <{0}> がコレクション内に存在しません。 + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} 文字列 '{0}' は文字列 '{1}' で始まりません。{2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index a6707c4ce1..bf3a47aa7d 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -358,6 +358,11 @@ Actual: {2} 컬렉션에 <{0}> 요소가 없습니다. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} '{0}' 문자열이 '{1}' 문자열로 시작되지 않습니다. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 1174de42f7..35c8e1b38f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -358,6 +358,11 @@ Rzeczywiste: {2} Elementy <{0}> nie występują w kolekcji. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} Ciąg „{0}” nie rozpoczyna się od ciągu „{1}”. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 2e6788a2d2..008fcb9592 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -358,6 +358,11 @@ Real: {2} O(s) elemento(s) <{0}> não está/estão presente(s) na coleção. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} A cadeia de caracteres “{0}” não começa com a cadeia de caracteres “{1}”. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index 37f23e6a2a..a8a44bbf6f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -358,6 +358,11 @@ Actual: {2} Элементы <{0}> отсутствуют в коллекции. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} Строка "{0}" не начинается со строки "{1}". {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index 21c3eca9bc..acc183d47f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -358,6 +358,11 @@ Gerçekte olan: {2} Öğe(ler) <{0}> koleksiyonda mevcut değildir. + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} '{0}' dizesi, '{1}' dizesi ile başlamıyor. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 8d2e003c00..5ccacab36d 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -358,6 +358,11 @@ Actual: {2} 集合中不存在元素 <{0}>。 + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} 字符串 '{0}' 不以字符串 '{1}' 开头。{2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 9917c4d793..67e4738d5b 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -358,6 +358,11 @@ Actual: {2} 集合中不存在元素 <{0}>。 + + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. + {0} is the test method name. + String '{0}' does not start with string '{1}'. {2} 字串 '{0}' 不是以字串 '{1}' 開頭。{2} From 4670b61b6c33e5df445da8aa01d1de9e9f0f4488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 27 Apr 2026 13:08:53 +0200 Subject: [PATCH 2/4] Throw PlatformNotSupportedException on non-Windows instead of warning 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. --- .../TestMethod/STATestMethodAttribute.cs | 17 +---------------- .../Resources/FrameworkMessages.resx | 5 ++--- .../Resources/xlf/FrameworkMessages.cs.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.de.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.es.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.fr.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.it.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.ja.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.ko.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.pl.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.pt-BR.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.ru.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.tr.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.zh-Hans.xlf | 8 ++++---- .../Resources/xlf/FrameworkMessages.zh-Hant.xlf | 8 ++++---- 15 files changed, 55 insertions(+), 71 deletions(-) diff --git a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs index a9a0682ab2..0d83f0230f 100644 --- a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs @@ -76,22 +76,7 @@ public override async Task ExecuteAsync(ITestMethod testMethod) #if !NETFRAMEWORK if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - // STA (Single Threaded Apartment) is a Windows-only COM threading concept and is not - // supported on non-Windows platforms. The test is executed on the current thread without - // STA context, which is acceptable because STA has no meaning outside of Windows. - TestResult[] nonWindowsResults = await ExecuteCoreAsync(testMethod).ConfigureAwait(false); - string warning = string.Format( - CultureInfo.InvariantCulture, - FrameworkMessages.STATestMethodNonWindowsWarning, - testMethod.TestMethodName); - foreach (TestResult result in nonWindowsResults) - { - result.LogOutput = result.LogOutput is null - ? warning - : result.LogOutput + Environment.NewLine + warning; - } - - return nonWindowsResults; + throw new PlatformNotSupportedException(FrameworkMessages.STATestMethodNonWindowsNotSupported); } #endif diff --git a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx index c7ac505a54..90350e2434 100644 --- a/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx +++ b/src/TestFramework/TestFramework/Resources/FrameworkMessages.resx @@ -405,8 +405,7 @@ Actual: {2} Nested assert scopes are not allowed. Dispose the current scope before creating a new one. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. \ No newline at end of file diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf index 537794ddb0..92af94f70f 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.cs.xlf @@ -358,10 +358,10 @@ Skutečnost: {2} Elementy <{0}> se v kolekci nenachází. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf index 98c786c057..361def958a 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.de.xlf @@ -358,10 +358,10 @@ Tatsächlich: {2} Element(e) <{0}> ist/sind in der Auflistung nicht vorhanden. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf index 428a100452..9b86c3bb13 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.es.xlf @@ -358,10 +358,10 @@ Real: {2} Los elementos <{0}> no están presentes en la colección. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf index f669095e6b..fcd01ce0ee 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.fr.xlf @@ -358,10 +358,10 @@ Réel : {2} L’élément ou les éléments <{0}> n’est ou ne sont pas présent(s) dans la collection. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf index 14242cbdd2..0ae3b6e713 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.it.xlf @@ -358,10 +358,10 @@ Effettivo: {2} Gli elementi <{0}> non sono presenti nella raccolta. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf index 93e57a6e14..347c2f890e 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ja.xlf @@ -358,10 +358,10 @@ Actual: {2} 要素 <{0}> がコレクション内に存在しません。 - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf index bf3a47aa7d..1327c841d3 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ko.xlf @@ -358,10 +358,10 @@ Actual: {2} 컬렉션에 <{0}> 요소가 없습니다. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf index 35c8e1b38f..b275678564 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pl.xlf @@ -358,10 +358,10 @@ Rzeczywiste: {2} Elementy <{0}> nie występują w kolekcji. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf index 008fcb9592..b71a8b0911 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.pt-BR.xlf @@ -358,10 +358,10 @@ Real: {2} O(s) elemento(s) <{0}> não está/estão presente(s) na coleção. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf index a8a44bbf6f..614b3c3acf 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.ru.xlf @@ -358,10 +358,10 @@ Actual: {2} Элементы <{0}> отсутствуют в коллекции. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf index acc183d47f..f022bd7c10 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.tr.xlf @@ -358,10 +358,10 @@ Gerçekte olan: {2} Öğe(ler) <{0}> koleksiyonda mevcut değildir. - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf index 5ccacab36d..d55eae7400 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hans.xlf @@ -358,10 +358,10 @@ Actual: {2} 集合中不存在元素 <{0}>。 - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} diff --git a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf index 67e4738d5b..f306bbd038 100644 --- a/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf +++ b/src/TestFramework/TestFramework/Resources/xlf/FrameworkMessages.zh-Hant.xlf @@ -358,10 +358,10 @@ Actual: {2} 集合中不存在元素 <{0}>。 - - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - Test method '{0}' is marked with [STATestMethod] but STA is a Windows-only COM threading concept. The test was executed without STA context on the current (non-Windows) platform. - {0} is the test method name. + + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + [STATestMethod] is not supported on non-Windows platforms. STA (Single Threaded Apartment) is a Windows-only COM threading concept. Use [OSCondition(OperatingSystems.Windows)] to skip this test on non-Windows platforms. + String '{0}' does not start with string '{1}'. {2} From 9c1512c23460f31b1c533dac469eb4769989f9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Mon, 27 Apr 2026 14:47:20 +0200 Subject: [PATCH 3/4] Also throw on non-Windows .NET Framework (Mono) 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+. --- .../Attributes/TestMethod/STATestMethodAttribute.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs index 0d83f0230f..2e7b3adfe6 100644 --- a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs @@ -73,12 +73,14 @@ public override async Task ExecuteAsync(ITestMethod testMethod) return await ExecuteCoreAsync(testMethod).ConfigureAwait(false); } -#if !NETFRAMEWORK +#if NETFRAMEWORK + if (Environment.OSVersion.Platform != PlatformID.Win32NT) +#else if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) +#endif { throw new PlatformNotSupportedException(FrameworkMessages.STATestMethodNonWindowsNotSupported); } -#endif TestResult[]? results = null; var t = new Thread(() => results = ExecuteCoreAsync(testMethod).GetAwaiter().GetResult()) From 06a658725f069c5a05c6971b6fdfa77f6de76c44 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:12:25 +0000 Subject: [PATCH 4/4] Revert NETFRAMEWORK Mono check, keep simple #if !NETFRAMEWORK guard Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/8c15cc9b-8fd9-4ff5-8b6a-4465ba920aac Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com> --- .../Attributes/TestMethod/STATestMethodAttribute.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs index 2e7b3adfe6..0d83f0230f 100644 --- a/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/TestMethod/STATestMethodAttribute.cs @@ -73,14 +73,12 @@ public override async Task ExecuteAsync(ITestMethod testMethod) return await ExecuteCoreAsync(testMethod).ConfigureAwait(false); } -#if NETFRAMEWORK - if (Environment.OSVersion.Platform != PlatformID.Win32NT) -#else +#if !NETFRAMEWORK if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) -#endif { throw new PlatformNotSupportedException(FrameworkMessages.STATestMethodNonWindowsNotSupported); } +#endif TestResult[]? results = null; var t = new Thread(() => results = ExecuteCoreAsync(testMethod).GetAwaiter().GetResult())