VsixCommunity / Community.VisualStudio.Toolkit

Making it easier to write Visual Studio extensions
Other
249 stars 44 forks source link

Retrieving Solution and its children at startup results in an error in the Solution Explorer #419

Closed RobertvanderHulst closed 10 months ago

RobertvanderHulst commented 1 year ago

A recent change (most likely commit 7d555d2) in the Solution Item class has caused a negative side effect: When VS is opened and a solution is passed through the command line then when you enumerate the solution and its children then the solution explorer will show an error message: image Apparently the solution explorer is in some state then which does not allow generating correct Hierarchy Items or something like that. I have adjusted my code to check if the solution explorer can be accessed before enumerating the projects.

try
{
   var solwin = await VS.Windows.GetSolutionExplorerWindowAsync();
   enumProjects = solwin != null;
}
catch ( Exception)
{
   // This happens when the solution explorer is not visible yet
   // do not enum the projects then
   enumProjects = false;
}
if (enumProjects)
.
.

That solves the problem for me. I am not sure what exactly causes the problem, maybe someone else does ?