Skip to content

Commit cd2a7d6

Browse files
Merge pull request #351 from MariaSolOs/fix-error-get-solution
Add open solution check when getting current solution
2 parents 9c32305 + ce1d3e9 commit cd2a7d6

File tree

1 file changed

+7
-0
lines changed
  • src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution

1 file changed

+7
-0
lines changed

src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/Solutions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Runtime.InteropServices;
55
using System.Threading.Tasks;
6+
using Microsoft.Internal.VisualStudio.PlatformUI;
67
using Microsoft.VisualStudio;
78
using Microsoft.VisualStudio.Shell;
89
using Microsoft.VisualStudio.Shell.Interop;
@@ -24,6 +25,12 @@ internal Solutions()
2425
public async Task<Solution?> GetCurrentSolutionAsync()
2526
{
2627
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
28+
29+
if (!HierarchyUtilities.IsSolutionOpen)
30+
{
31+
return null;
32+
}
33+
2734
IVsHierarchy solution = (IVsHierarchy)await VS.Services.GetSolutionAsync();
2835
IVsHierarchyItem hierItem = await solution.ToHierarchyItemAsync(VSConstants.VSITEMID_ROOT);
2936
return SolutionItem.FromHierarchyItem(hierItem) as Solution;

0 commit comments

Comments
 (0)