Skip to content

Force initialize EnvDTE.Project because EnvDTE.Project initialization does not specify its thread affinity - #7292

Merged
nkolev92 merged 4 commits into
devfrom
dev-nkolev92-aggressiveInitEnvDTEProject
Apr 16, 2026
Merged

nkolev92 merged 4 commits into
devfrom
dev-nkolev92-aggressiveInitEnvDTEProject

Conversation

@nkolev92

@nkolev92 nkolev92 commented Apr 16, 2026 •

Copy link
Copy Markdown
Member

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-Project ended 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:

public static EnvDTE.Project GetProjectFromHierarchy(IVsHierarchy pHierarchy)

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

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests (Thanks for writing the test @donnie-msft )
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@nkolev92
nkolev92 marked this pull request as ready for review April 16, 2026 20:46
@nkolev92
nkolev92 requested a review from a team as a code owner April 16, 2026 20:46
@nkolev92
nkolev92 requested review from kartheekp-ms and zivkan April 16, 2026 20:46
@nkolev92 nkolev92 changed the title Force initialize EnvDTE.Project because other code has bugs Force initialize EnvDTE.Project because EnvDTE.Project initialization does not specify its thread affinity Apr 16, 2026
@nkolev92
nkolev92 enabled auto-merge (squash) April 16, 2026 21:45
@nkolev92
nkolev92 merged commit 106309a into dev Apr 16, 2026
17 of 18 checks passed
@nkolev92
nkolev92 deleted the dev-nkolev92-aggressiveInitEnvDTEProject branch April 16, 2026 23:09
nkolev92 added a commit that referenced this pull request Apr 16, 2026
nkolev92 added a commit that referenced this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error while using Add-Migration in nuget console in Visual Studio Insiders 18.6

5 participants