Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix COM test failures on Windows Nano Server #57148

Merged
2 commits merged into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down
43 changes: 27 additions & 16 deletions src/tests/Interop/COM/NETClients/Lifetime/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}