Unable to Cast Solution.Projects to EnvDTE.Project in Visual Studio 2022 - Casting Error

Timi 0 Reputation points
2025-03-29T07:35:58.2966667+00:00

I’m facing an issue where my custom tool fails when trying to access the Solution.Projects collection and cast its elements to EnvDTE.Project in Visual Studio 2022. The same code was working in older VS versions without issues, but after upgrading to Visual Studio 2022, I encounter a casting error.

foreach (EnvDTE.Project project in prj.DTE.Solution.Projects)
{
    // try to access properties 
}

Unable to cast object of type 'Microsoft.VisualStudio.CommonIDE.Solutions.Dte.DteProjects' to type 'EnvDTE.Projects'.

Is this a bug or should I be handling the Solution.Projects collection differently in VS 2022?

Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
275 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.