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

Package load failure when trying to lauch Navigate To after opening a solution #30892

Closed
shyamnamboodiripad opened this issue Nov 1, 2018 · 4 comments
Assignees
Labels
Area-IDE Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@shyamnamboodiripad
Copy link
Contributor

Version Used: VS 16.0 P1 build 28231.51.d16.0

Steps to Reproduce:

  1. Open a solution in VS without any files open in the editor
  2. Ctrl + , to launch Navigate To
  3. Search for some type

Note: Problem does not repro if you already had some files from the solution open in the editor at the point where Navigate To was launched.

Expected Behavior: Should succeed

Actual Behavior: Following package load failure error -

image

On debugging the underlying issue appears to be that AbstractNavigateToSearchService is trying to instantiate VisualStudioExperimentationService from the background thread resulting in an InvalidOperationException from the following Contract.ThrowIfFalse() call.

Dump file: Available at \\<internalshare>\\<myfolder>\Dumps\RoslynPackageLoad

      Microsoft.CodeAnalysis.Workspaces.dll!Roslyn.Utilities.Contract.ThrowIfFalse(bool condition, string message) Line 32  C#
Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Shared.Utilities.ForegroundThreadAffinitizedObject.AssertIsForeground() Line 56   C#
Microsoft.CodeAnalysis.EditorFeatures.dll!Microsoft.CodeAnalysis.Editor.Shared.Utilities.ForegroundThreadAffinitizedObject.ForegroundThreadAffinitizedObject(Microsoft.CodeAnalysis.Editor.Shared.Utilities.IThreadingContext threadingContext, bool assertIsForeground) Line 34   C#
> Microsoft.VisualStudio.LanguageServices.dll!Microsoft.VisualStudio.LanguageServices.Experimentation.VisualStudioExperimentationService.VisualStudioExperimentationService(Microsoft.CodeAnalysis.Editor.Shared.Utilities.IThreadingContext threadingContext, Microsoft.VisualStudio.Shell.SVsServiceProvider serviceProvider) Line 27   C#
              [Native to Managed Transition]      
              [Managed to Native Transition]      
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.ReflectionHelpers.Instantiate(System.Reflection.MethodBase ctorOrFactoryMethod, object[] arguments) Line 595  C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue() Line 517 C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create() Line 1160             C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleState nextState) Line 1255          C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleState requiredState) Line 1336   C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose() Line 1061             C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.ExportProvider.CreateExport.AnonymousMethod__0() Line 461 C#
              mscorlib.dll!System.Lazy<object>.CreateValue() Line 437         C#
              mscorlib.dll!System.Lazy<object>.LazyInitValue() Line 388       C#
              mscorlib.dll!System.Lazy<object>.Value.get() Line 339             C#
Microsoft.VisualStudio.Composition.dll!Microsoft.VisualStudio.Composition.NetFxAdapters.MefV1ExportProvider.UnwrapExport.AnonymousMethod__1() Line 246 C#
System.ComponentModel.Composition.dll!System.ComponentModel.Composition.Primitives.Export.GetExportedValueCore() Line 247 C#
System.ComponentModel.Composition.dll!System.ComponentModel.Composition.Primitives.Export.Value.get() Line 207 C#
System.ComponentModel.Composition.dll!System.ComponentModel.Composition.ExportServices.GetCastedExportedValue<Microsoft.CodeAnalysis.Host.IWorkspaceService>(System.ComponentModel.Composition.Primitives.Export export) Line 135  C#
System.ComponentModel.Composition.dll!System.ComponentModel.Composition.ExportServices.CreateStronglyTypedLazyOfTM.AnonymousMethod__1() Line 88   C#
mscorlib.dll!System.Lazy<Microsoft.CodeAnalysis.Host.IWorkspaceService>.CreateValue() Line 437 C#
mscorlib.dll!System.Lazy<Microsoft.CodeAnalysis.Host.IWorkspaceService>.LazyInitValue() Line 359 C#
mscorlib.dll!System.Lazy<Microsoft.CodeAnalysis.Host.IWorkspaceService>.Value.get() Line 339 C#
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.GetService<Microsoft.CodeAnalysis.Experiments.IExperimentationService>() Line 49   C#
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Remote.RemoteHostClientExtensions.IsOutOfProcessEnabled(Microsoft.CodeAnalysis.Workspace workspace, Microsoft.CodeAnalysis.Options.Option<bool> featureOption) Line 129              C#
Microsoft.CodeAnalysis.Workspaces.dll!Microsoft.CodeAnalysis.Remote.RemoteHostClientExtensions.TryGetRemoteHostClientAsync(Microsoft.CodeAnalysis.Workspace workspace, Microsoft.CodeAnalysis.Options.Option<bool> featureOption, System.Threading.CancellationToken cancellationToken) Line 135         C#
Microsoft.CodeAnalysis.Features.dll!Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.TryGetRemoteHostClientAsync(Microsoft.CodeAnalysis.Project project, System.Threading.CancellationToken cancellationToken) Line 47           C#
Microsoft.CodeAnalysis.Features.dll!Microsoft.CodeAnalysis.NavigateTo.AbstractNavigateToSearchService.SearchProjectAsync(Microsoft.CodeAnalysis.Project project, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Document> priorityDocuments, string searchPattern, System.Collections.Immutable.IImmutableSet<string> kinds, System.Threading.CancellationToken cancellationToken)        C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo.NavigateToItemProvider.Searcher.SearchAsyncWorker(Microsoft.CodeAnalysis.Project project, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Document> priorityDocuments) Line 189           C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo.NavigateToItemProvider.Searcher.SearchAsync(Microsoft.CodeAnalysis.Project project, System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Document> priorityDocuments)           C#
Microsoft.CodeAnalysis.EditorFeatures.Wpf.dll!Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo.NavigateToItemProvider.Searcher.SearchProjectsInPriorityOrder.AnonymousMethod__5() Line 146 C#
mscorlib.dll!System.Threading.Tasks.Task<System.Threading.Tasks.Task>.InnerInvoke() Line 680 C#
              mscorlib.dll!System.Threading.Tasks.Task.Execute() Line 2498 C#
              mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj) Line 2861      C#
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 954 C#
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 902 C#
              mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Line 2827         C#
              mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Line 2756            C#
mscorlib.dll!System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() Line 2704             C#
              mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 820              C#
           mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() Line 1161             C#
@shyamnamboodiripad
Copy link
Contributor Author

shyamnamboodiripad commented Nov 1, 2018

cc @sharwell @jasonmalinowski @jinujoseph

This is a regression and we should ideally address this soon since it can affect dogfooding.

@sharwell
Copy link
Member

sharwell commented Nov 1, 2018

I see two primary ways to resolve this:

  1. Use JTF in the constructor to remove the caller affinity requirement.
  2. Make IsExperimentEnabled an asynchronous method that lazily initializes the function. In can return ValueTask<bool> since the majority case (after initialization) doesn't need to jump to the main thread again.

@davkean
Copy link
Member

davkean commented Nov 8, 2018

The fix here sharwell@9ddfbf0 is incorrect, JFT.Run shouldn't be used in MEF constructors and can lead to deadlocks and possible thread-starvation, please see: https://github.com/Microsoft/vs-threading/blob/master/doc/cookbook_vs.md#how-do-i-effectively-verify-that-my-code-is-fully-free-threaded, in particular:

It is not always necessary for code to be free-threaded. There are many cases where code must run on the main thread because it calls into other code that itself has thread-affinity or is not thread-safe. Important places to be free-threaded include:

  1. Code that runs in the MEF activation code paths (e.g. importing constructors, OnImportsSatisfied callbacks, and any code called therefrom).

We just recently removed a bunch of these across the product. The pattern elsewhere is to wrap this in an AsyncLazy<T> and just switch to the UI thread on first access.

@sharwell
Copy link
Member

sharwell commented Nov 8, 2018

@davkean The fix there is an interim solution only. A proper fix is in a follow-up PR (#30929) for preview 2.

@sharwell sharwell added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 4 - In Review A fix for the issue is submitted for review. labels Nov 8, 2018
@ghost ghost closed this as completed in 9ddfbf0 Nov 9, 2018
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

3 participants