Repository navigation
Force initialize EnvDTE.Project because EnvDTE.Project initialization does not specify its thread affinity - #7292
Merged
Conversation
nkolev92
marked this pull request as ready for review
April 16, 2026 20:46
jeffkl
approved these changes
Apr 16, 2026
jebriede
approved these changes
Apr 16, 2026
zivkan
approved these changes
Apr 16, 2026
3 tasks
donnie-msft
approved these changes
Apr 16, 2026
nkolev92
enabled auto-merge (squash)
April 16, 2026 21:45
nkolev92
added a commit
that referenced
this pull request
Apr 16, 2026
… does not specify its thread affinity (#7292)
3 tasks done
This was referenced Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#14862
Description
Ensure the EnvDTE.Project is initialized.
Under the hood VSProjectAdapter actually has a Lazy<EnvDte.project>, which needs the UI thread to satisfy the cast.
If PMC is actually the first one that wants the EnvDTE.Project, it would fail because it's being called from the pipeline thread.
This is a workaround to make sure the EnvDTE.Project is initialized before any PMC code tries to use it.
The code change that regressed is bff510e.
In that code change, UnconfiguredProject acquisition was lazified, but unfortunately that also meant we never actualized EnvDTE.Project and the PMC command call
Get-Projectended up being the first one needing it.Basically, that change, exposed a bug in the VSProjectAdapter implementation where an STA dependent callwas being performed in a lazy that simply cannot ensure we were on the correct thread.
The code that does the conversion is here:
NuGet.Client/src/NuGet.Clients/NuGet.VisualStudio.Common/IDE/VsHierarchyUtility.cs
Line 135 in 1f130f6
This is the simplest fix, but probably not the ideal one.
For the test, note that we verified it failed without my fix and passed with it. cc @donnie-msft
PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.