diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs index d01d79f153db49..1738dbc08affca 100644 --- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.Marshalling.cs @@ -47,7 +47,8 @@ static int Main(string[] doNotUse) ValidatePInvokes(validateUseRegistered: false); } - if(!builtInComDisabled) + // RegFree COM is not supported on Windows Nano Server + if(!builtInComDisabled && !Utilities.IsWindowsNanoServer) { // This calls ValidateNativeServerActivation which calls Marshal.GetTypeFromCLSID that is not supported ValidateComActivation(validateUseRegistered: true); diff --git a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs index 0eaa5facfae1ed..dd8ea4f5f3e858 100644 --- a/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs +++ b/src/tests/Interop/COM/ComWrappers/GlobalInstance/GlobalInstance.TrackerSupport.cs @@ -33,7 +33,7 @@ static int Main(string[] doNotUse) ValidateRegisterForTrackerSupport(); #if Windows ValidateNotRegisteredForMarshalling(); -#endif +#endif IntPtr trackerObjRaw = MockReferenceTrackerRuntime.CreateTrackerObject(); var trackerObj = GlobalComWrappers.Instance.GetOrCreateObjectForComInstance(trackerObjRaw, CreateObjectFlags.TrackerObject); @@ -50,8 +50,12 @@ static int Main(string[] doNotUse) ValidatePInvokes(validateUseRegistered: true); ValidatePInvokes(validateUseRegistered: false); - ValidateComActivation(validateUseRegistered: true); - ValidateComActivation(validateUseRegistered: false); + // RegFree COM is not supported on Windows Nano Server + if (!Utilities.IsWindowsNanoServer) + { + ValidateComActivation(validateUseRegistered: true); + ValidateComActivation(validateUseRegistered: false); + } #endif ValidateNotifyEndOfReferenceTrackingOnThread(); } diff --git a/src/tests/Interop/COM/NETClients/Lifetime/Program.cs b/src/tests/Interop/COM/NETClients/Lifetime/Program.cs index a8a5132ded8768..ee6fb79fcc5143 100644 --- a/src/tests/Interop/COM/NETClients/Lifetime/Program.cs +++ b/src/tests/Interop/COM/NETClients/Lifetime/Program.cs @@ -81,31 +81,42 @@ static void Validate_COMServer_DisableEagerCleanUp() Assert.IsFalse(Marshal.AreComObjectsAvailableForCleanup()); } - [STAThread] static int Main(string[] doNotUse) { - // RegFree COM is not supported on Windows Nano + // RegFree COM and STA apartments are not supported on Windows Nano if (Utilities.IsWindowsNanoServer) { return 100; } - try - { - // Initialization for all future tests - Initialize(); - Assert.IsTrue(GetAllocationCount != null); + int result = 101; - Validate_COMServer_CleanUp(); - Validate_COMServer_DisableEagerCleanUp(); - } - catch (Exception e) + // Run the test on a new STA thread since Nano Server doesn't support the STA + // and as a result, the main application thread can't be made STA with the STAThread attribute + Thread staThread = new Thread(() => { - Console.WriteLine($"Test Failure: {e}"); - return 101; - } - - return 100; + try + { + // Initialization for all future tests + Initialize(); + Assert.IsTrue(GetAllocationCount != null); + + Validate_COMServer_CleanUp(); + Validate_COMServer_DisableEagerCleanUp(); + } + catch (Exception e) + { + Console.WriteLine($"Test Failure: {e}"); + result = 101; + } + result = 100; + }); + + staThread.SetApartmentState(ApartmentState.STA); + staThread.Start(); + staThread.Join(); + + return result; } } }