Skip to content

Commit

Permalink
Fix an apartment state issue (partial port of dotnet#19384)
Browse files Browse the repository at this point in the history
Partial port of dotnet#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
  • Loading branch information
kouvel committed Aug 16, 2018
1 parent 0e1a827 commit dd14ba8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3078,8 +3078,9 @@ void SystemDomain::SetThreadAptState (Thread::ApartmentState state)
Thread::ApartmentState pState = pThread->SetApartment(Thread::AS_InSTA, TRUE);
_ASSERTE(pState == Thread::AS_InSTA);
}
else if (state == Thread::AS_InMTA)
else
{
// If an apartment state was not explicitly requested, default to MTA
Thread::ApartmentState pState = pThread->SetApartment(Thread::AS_InMTA, TRUE);
_ASSERTE(pState == Thread::AS_InMTA);
}
Expand Down
6 changes: 1 addition & 5 deletions src/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,11 +1798,7 @@ INT32 Assembly::ExecuteMainMethod(PTRARRAYREF *stringArgs, BOOL waitForOtherThre

Thread::ApartmentState state = Thread::AS_Unknown;
state = SystemDomain::GetEntryPointThreadAptState(pMeth->GetMDImport(), pMeth->GetMemberDef());

// If the entry point has an explicit thread apartment state, set it
// before running the AppDomainManager initialization code.
if (state == Thread::AS_InSTA || state == Thread::AS_InMTA)
SystemDomain::SetThreadAptState(state);
SystemDomain::SetThreadAptState(state);
#endif // FEATURE_COMINTEROP
}

Expand Down

0 comments on commit dd14ba8

Please sign in to comment.