Flow-Launcher/Flow.Launcher · error · Exception

GetUIObjectOf failed

Error message

GetUIObjectOf failed

What it means

Thrown when IShellFolder.GetUIObjectOf returns non-zero while asking the parent folder for an IContextMenu on the child PIDL. GetUIObjectOf is how the Shell hands out per-item COM interfaces; a failure means the parent folder cannot, or will not, produce a context menu for this child. The HRESULT is discarded. This is the third link in the PIDL -> parent -> IContextMenu chain inside ExecuteContextMenuItem.

Source

Thrown at Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs:198

        IShellFolder shellFolder = null;

        try
        {
            malloc = GetMalloc();
            var hr = SHParseDisplayName(fileName, IntPtr.Zero, out var pidl, 0, out _);
            if (hr != 0) throw new Exception("SHParseDisplayName failed");

            originalPidl = pidl;

            var guid = typeof(IShellFolder).GUID;
            hr = SHBindToParent(pidl, guid, out pShellFolder, ref pidl);
            if (hr != 0) throw new Exception("SHBindToParent failed");

            shellFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(pShellFolder, typeof(IShellFolder));
            hr = shellFolder.GetUIObjectOf(
                IntPtr.Zero, 1, new[] { pidl }, typeof(IContextMenu).GUID, IntPtr.Zero, out pContextMenu
            );
            if (hr != 0) throw new Exception("GetUIObjectOf failed");

            contextMenu = (IContextMenu)Marshal.GetTypedObjectForIUnknown(pContextMenu, typeof(IContextMenu));

            hMenu = CreatePopupMenu();
            contextMenu.QueryContextMenu(hMenu, 0, ContextMenuStartId, ContextMenuEndId, (uint)ContextMenuFlags.Explore);

            var directory = Path.GetDirectoryName(fileName);
            var invokeCommandInfo = new CMINVOKECOMMANDINFO
            {
                cbSize = (uint)Marshal.SizeOf(typeof(CMINVOKECOMMANDINFO)),
                fMask = (uint)ContextMenuInvokeCommandFlags.Unicode,
                hwnd = IntPtr.Zero,
                lpVerb = (IntPtr)(menuItemId - ContextMenuStartId),
                lpParameters = null,
                lpDirectory = null,
                nShow = 1,
                hIcon = IntPtr.Zero,
            };

View on GitHub (pinned to 7fc63b07bb)

Solutions

  1. Preserve the HRESULT: throw new COMException("GetUIObjectOf failed", hr).
  2. Fall back to a default Flow Launcher action menu when GetUIObjectOf fails, rather than aborting the whole operation.
  3. Try the SHELL namespace IExplorerCommand interface or SHCreateDefaultContextMenu as an alternative when IContextMenu is refused.
  4. Verify the file is hydrated/available (e.g. File.Exists, attributes check) before requesting the menu.

Example fix

// before
hr = shellFolder.GetUIObjectOf(IntPtr.Zero, 1, new[] { pidl }, typeof(IContextMenu).GUID, IntPtr.Zero, out pContextMenu);
if (hr != 0) throw new Exception("GetUIObjectOf failed");

// after
hr = shellFolder.GetUIObjectOf(IntPtr.Zero, 1, new[] { pidl }, typeof(IContextMenu).GUID, IntPtr.Zero, out pContextMenu);
if (hr != 0) throw new COMException("GetUIObjectOf failed", hr);
Defensive patterns

Strategy: fallback

Validate before calling

// No reliable pre-check; verify hydration/availability as a proxy.
var attrs = File.GetAttributes(fileName);
if ((attrs & FileAttributes.Offline) != 0) logger.Warn($"Item is offline: {fileName}");

Type guard

static bool LooksHydrated(string path) { try { return !File.GetAttributes(path).HasFlag(FileAttributes.Offline); } catch { return false; } }

Try / catch

try { ShellContextMenuDisplayHelper.ExecuteContextMenuItem(fileName, menuItemId); }
catch (Exception ex) when (ex.Message == "GetUIObjectOf failed")
{
    ShowFallbackMenu(fileName); // built-in Open / Copy path
}

Prevention

When it happens

Trigger: Asking for IContextMenu on a non-interactive item (a disconnected network placeholder, an item in a read-only namespace, an item type whose shell extension context-menu handler crashed or was disabled), permission/ACL mismatch where the user cannot enumerate the item, or the child PIDL passed in does not match what the parent expects.

Common situations: The file lives in a OneDrive/SharePoint folder that is online-only and not hydrated; an installed shell extension (antivirus, cloud sync) that registers IContextMenu crashes on this file type; running elevated vs non-elevated mismatch where the parent folder was bound in a different integrity level.

Related errors


AI-assisted analysis of Flow-Launcher/Flow.Launcher@7fc63b07bb (2026-08-13). Data as JSON: /api/errors/698bdf8ac4d38ad4. Report an issue: GitHub.