Failing after upgrading to netcore3.1 and netstandard2.1: "cannot call GetService from a background thread in an AsyncPackage derived class."
brennfoster opened this issue · comments
System.InvalidOperationException: Due to high risk of deadlock you cannot call GetService from a background thread in an AsyncPackage derived class. You should instead call GetServiceAsync (without calling Result or Wait on the resultant Task object) or switch to the UI thread with the JoinableTaskFactory.SwitchToMainThreadAsync method before calling GetService.
at Microsoft.VisualStudio.Shell.AsyncPackage.GetService(Type serviceType)
at Microsoft.VisualStudio.Shell.Package.System.IServiceProvider.GetService(Type serviceType)
at Microsoft.VisualStudio.Shell.Package.PackageContainer.GetService(Type serviceType)
at System.ComponentModel.Container.Site.GetService(Type service)
at System.ComponentModel.Component.GetService(Type service)
at Microsoft.VisualStudio.Shell.DialogPage.get_SettingsMananger()
at Microsoft.VisualStudio.Shell.DialogPage.LoadSettingsFromStorage()
at LicenseHeaderManager.Options.VersionedDialogPage.LoadSettingsFromStorage() in C:\Build\1776828f99d31c99\LicenseHeaderManager\Options\VersionedDialogPage.cs:line 37
at Microsoft.VisualStudio.Shell.DialogPage.set_Site(ISite value)
at System.ComponentModel.Container.Add(IComponent component, String name)
at System.ComponentModel.Container.Add(IComponent component)
at Microsoft.VisualStudio.Shell.Package.GetDialogPage(Type dialogPageType)
at LicenseHeaderManager.LicenseHeadersPackage.get_LanguagesPage() in C:\Build\1776828f99d31c99\LicenseHeaderManager\LicenseHeadersPackage.cs:line 740
at LicenseHeaderManager.Headers.LicenseHeaderReplacer.TryCreateDocument(ProjectItem item, Document& document, Boolean& wasOpen, IDictionary2 headers) in C:\Build\1776828f99d31c99\LicenseHeaderManager\Headers\LicenseHeaderReplacer.cs:line 208 at LicenseHeaderManager.Headers.LicenseHeaderReplacer.RemoveOrReplaceHeaderRecursive(ProjectItem item, IDictionary
2 headers, Boolean searchForLicenseHeaders) in C:\Build\1776828f99d31c99\LicenseHeaderManager\Headers\LicenseHeaderReplacer.cs:line 119
at LicenseHeaderManager.Headers.LicenseHeaderReplacer.RemoveOrReplaceHeaderRecursive(ProjectItem item, IDictionary2 headers, Boolean searchForLicenseHeaders) in C:\Build\1776828f99d31c99\LicenseHeaderManager\Headers\LicenseHeaderReplacer.cs:line 178 at LicenseHeaderManager.PackageCommands.AddLicenseHeaderToAllFilesInProjectCommand.Execute(Object projectOrProjectItem) in C:\Build\1776828f99d31c99\LicenseHeaderManager\PackageCommands\AddLicenseHeaderToAllFilesInProjectCommand.cs:line 62 at LicenseHeaderManager.PackageCommands.AddLicenseHeaderToAllFilesInSolutionCommand.AddLicenseHeaderToProjects(List
1 projectsInSolution) in C:\Build\1776828f99d31c99\LicenseHeaderManager\PackageCommands\AddLicenseHeaderToAllFilesInSolutionCommand.cs:line 141
at LicenseHeaderManager.PackageCommands.AddLicenseHeaderToAllFilesInSolutionCommand.Execute(Solution solution) in C:\Build\1776828f99d31c99\LicenseHeaderManager\PackageCommands\AddLicenseHeaderToAllFilesInSolutionCommand.cs:line 64
at LicenseHeaderManager.ButtonHandler.SolutionLevelButtonThreadWorker.Run(Object solutionObject) in C:\Build\1776828f99d31c99\LicenseHeaderManager\ButtonHandler\SolutionLevelButtonThreadWorker.cs:line 40
Hi @brennfoster,
This looks like a duplicate of #116.
Could you confirm that? There's also a workaround there. I'd close your issue in favor of the other one.
Best regards,
Stefan