From 4dbda7f0c69822782ab6c9cb79a9cf0c7597a2b0 Mon Sep 17 00:00:00 2001 From: Ruofan Date: Sun, 12 Jan 2025 03:15:00 +0800 Subject: [PATCH] Fixed #488 that ShellFolder.EnumerateChildIds might throw NullReferenceException if failed to enum the objects (#499) --- Windows.Shell.Common/ShellObjects/ShellFolder.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Windows.Shell.Common/ShellObjects/ShellFolder.cs b/Windows.Shell.Common/ShellObjects/ShellFolder.cs index fe76f5084..dacb9035d 100644 --- a/Windows.Shell.Common/ShellObjects/ShellFolder.cs +++ b/Windows.Shell.Common/ShellObjects/ShellFolder.cs @@ -204,7 +204,11 @@ public IEnumerable EnumerateChildren(FolderItemFilter filter /*= Fold public IEnumerable EnumerateChildIds(FolderItemFilter filter /*= FolderItemFilter.Folders | FolderItemFilter.IncludeHidden | FolderItemFilter.NonFolders | FolderItemFilter.IncludeSuperHidden */, HWND parentWindow = default, int fetchSize = 20) { if (iShellFolder.EnumObjects(parentWindow, (SHCONTF)filter, out var eo).Failed) + { Debug.WriteLine($"Unable to enum children in folder."); + yield break; + } + try { foreach (PIDL p in eo!.Enumerate(fetchSize))