diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/PhysicalFile.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/PhysicalFile.cs index 903a608..110233f 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/PhysicalFile.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/PhysicalFile.cs @@ -225,7 +225,7 @@ public static async Task> FromFilesAsync(params string /// /// Known attributes of a . - /// This can be used to set an attribute of a file using the method. + /// This can be used to set an attribute of a file using the method. /// public enum PhysicalFileAttribute { diff --git a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs index 2b5a961..6431d07 100644 --- a/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs +++ b/src/toolkit/Community.VisualStudio.Toolkit.Shared/Solution/SolutionItem.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using System.Windows.Automation.Peers; using Microsoft.Internal.VisualStudio.PlatformUI; using Microsoft.VisualStudio; using Microsoft.VisualStudio.Shell; @@ -146,16 +147,24 @@ public void GetItemInfo(out IVsHierarchy hierarchy, out uint itemId, out IVsHier SolutionItemType type = GetSolutionItemType(item.HierarchyIdentity); - return type switch + try { - SolutionItemType.Solution => new Solution(item, type), - SolutionItemType.Project => new Project(item, type), - SolutionItemType.PhysicalFile => new PhysicalFile(item, type), - SolutionItemType.PhysicalFolder => new PhysicalFolder(item, type), - SolutionItemType.VirtualFolder => new VirtualFolder(item, type), - SolutionItemType.SolutionFolder => new SolutionFolder(item, type), - _ => new SolutionItem(item, type) - }; + return type switch + { + SolutionItemType.Solution => new Solution(item, type), + SolutionItemType.Project => new Project(item, type), + SolutionItemType.PhysicalFile => new PhysicalFile(item, type), + SolutionItemType.PhysicalFolder => new PhysicalFolder(item, type), + SolutionItemType.VirtualFolder => new VirtualFolder(item, type), + SolutionItemType.SolutionFolder => new SolutionFolder(item, type), + _ => new SolutionItem(item, type) + }; + } + catch + { + // If we failed to create the item, we should return null. + return null; + } } private static SolutionItemType GetSolutionItemType(IVsHierarchyItemIdentity identity)