Skip to content

Commit 43b9c5b

Browse files
Fixed handling of empty solutions
[release]
1 parent c71e69b commit 43b9c5b

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static async Task<IEnumerable<PhysicalFile>> FromFilesAsync(params string
225225

226226
/// <summary>
227227
/// Known attributes of a <see cref="PhysicalFile"/>.
228-
/// This can be used to set an attribute of a file using the <see cref="PhysicalFile.TrySetAttributeAsync(PhysicalFileAttribute, string)"/> method.
228+
/// This can be used to set an attribute of a file using the <see cref="PhysicalFile.TrySetAttributeAsync(PhysicalFileAttribute, object)"/> method.
229229
/// </summary>
230230
public enum PhysicalFileAttribute
231231
{

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using System.Windows.Automation.Peers;
67
using Microsoft.Internal.VisualStudio.PlatformUI;
78
using Microsoft.VisualStudio;
89
using Microsoft.VisualStudio.Shell;
@@ -146,16 +147,24 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier
146147

147148
SolutionItemType type = GetSolutionItemType(item.HierarchyIdentity);
148149

149-
return type switch
150+
try
150151
{
151-
SolutionItemType.Solution => new Solution(item, type),
152-
SolutionItemType.Project => new Project(item, type),
153-
SolutionItemType.PhysicalFile => new PhysicalFile(item, type),
154-
SolutionItemType.PhysicalFolder => new PhysicalFolder(item, type),
155-
SolutionItemType.VirtualFolder => new VirtualFolder(item, type),
156-
SolutionItemType.SolutionFolder => new SolutionFolder(item, type),
157-
_ => new SolutionItem(item, type)
158-
};
152+
return type switch
153+
{
154+
SolutionItemType.Solution => new Solution(item, type),
155+
SolutionItemType.Project => new Project(item, type),
156+
SolutionItemType.PhysicalFile => new PhysicalFile(item, type),
157+
SolutionItemType.PhysicalFolder => new PhysicalFolder(item, type),
158+
SolutionItemType.VirtualFolder => new VirtualFolder(item, type),
159+
SolutionItemType.SolutionFolder => new SolutionFolder(item, type),
160+
_ => new SolutionItem(item, type)
161+
};
162+
}
163+
catch
164+
{
165+
// If we failed to create the item, we should return null.
166+
return null;
167+
}
159168
}
160169

161170
private static SolutionItemType GetSolutionItemType(IVsHierarchyItemIdentity identity)

0 commit comments

Comments
 (0)