diff --git a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs index 25c72e285146c..08625ae785da0 100644 --- a/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs +++ b/src/VisualStudio/Core/Def/Implementation/LanguageService/AbstractPackage`2.cs @@ -19,6 +19,7 @@ using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Threading; +using Roslyn.Utilities; using Task = System.Threading.Tasks.Task; namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService @@ -41,6 +42,9 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke { await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true); + await TaskScheduler.Default; + _componentModel_doNotAccessDirectly = await this.GetServiceAsync(throwOnFailure: true).ConfigureAwait(false); + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var shell = (IVsShell7)await GetServiceAsync(typeof(SVsShell)).ConfigureAwait(true); @@ -106,11 +110,7 @@ internal IComponentModel ComponentModel { get { - ThreadHelper.ThrowIfNotOnUIThread(); - - if (_componentModel_doNotAccessDirectly == null) - _componentModel_doNotAccessDirectly = (IComponentModel)GetService(typeof(SComponentModel)); - + Contract.ThrowIfNull(_componentModel_doNotAccessDirectly); return _componentModel_doNotAccessDirectly; } }