Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 14d728a

Browse files
kouvelKoundinya Veluri
authored andcommitted
Fix an apartment state issue (partial port of #19384)
Partial port of #19384 to 2.2 Fix for https://github.com/dotnet/coreclr/issues/17822 - The apartment state now defaults to MTA for the main thread along with a CoInitialize - Calling `Thread.SetApartmentState` with STA now fails as expected (different behavior from previous netcore, same behavior as netfx) Fix for https://github.com/dotnet/coreclr/issues/19225
1 parent 1d61034 commit 14d728a

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/vm/appdomain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3078,8 +3078,9 @@ void SystemDomain::SetThreadAptState (Thread::ApartmentState state)
30783078
Thread::ApartmentState pState = pThread->SetApartment(Thread::AS_InSTA, TRUE);
30793079
_ASSERTE(pState == Thread::AS_InSTA);
30803080
}
3081-
else if (state == Thread::AS_InMTA)
3081+
else
30823082
{
3083+
// If an apartment state was not explicitly requested, default to MTA
30833084
Thread::ApartmentState pState = pThread->SetApartment(Thread::AS_InMTA, TRUE);
30843085
_ASSERTE(pState == Thread::AS_InMTA);
30853086
}

src/vm/assembly.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,11 +1798,7 @@ INT32 Assembly::ExecuteMainMethod(PTRARRAYREF *stringArgs, BOOL waitForOtherThre
17981798

17991799
Thread::ApartmentState state = Thread::AS_Unknown;
18001800
state = SystemDomain::GetEntryPointThreadAptState(pMeth->GetMDImport(), pMeth->GetMemberDef());
1801-
1802-
// If the entry point has an explicit thread apartment state, set it
1803-
// before running the AppDomainManager initialization code.
1804-
if (state == Thread::AS_InSTA || state == Thread::AS_InMTA)
1805-
SystemDomain::SetThreadAptState(state);
1801+
SystemDomain::SetThreadAptState(state);
18061802
#endif // FEATURE_COMINTEROP
18071803
}
18081804

0 commit comments

Comments
 (0)