Skip to content

Calls to IVsHierarchy.GetHierarchy should be on the UI thread #6940

@ryzngard

Description

@ryzngard

GetHierarchy returns a UI affinitized object, so it should always be on the UI thread. With Roslyn 35746 a foreground assert was added, and this appears to be causing problems when debugging.

Here's an example stack trace

---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----
When created thread id  : 1
When created thread name: 
Current thread id       : 20
Current thread name     : 
---- Assert Long Message ----

   at Microsoft.CodeAnalysis.Editor.Shared.Utilities.ForegroundThreadAffinitizedObject.AssertIsForeground()
   at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.VisualStudioWorkspaceImpl.GetHierarchy(ProjectId projectId)
   at <StartupCode$FSharp-Editor>.$FSharpProjectOptionsManager.clo@183-19.Invoke(Unit unitVar)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2)
   at Microsoft.FSharp.Control.AsyncPrimitives.unitAsync@607.Invoke(AsyncActivation`1 ctxt)
   at <StartupCode$FSharp-Core>.$Mailbox.processFirstArrival@344-8.Invoke(AsyncActivation`1 ctxt)
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction)
   at Microsoft.FSharp.Control.TrampolineHolder.ExecuteWithTrampoline(FSharpFunc`2 firstAction)
   at <StartupCode$FSharp-Core>.$Async.AwaitWaitHandle@1421-3.Invoke(Object _arg5, Boolean timeOut)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context(Object state, Boolean timedOut)
   at System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context_f(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

@TIHan @KevinRansom

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions