{"record":{"id":"698bdf8ac4d38ad4","repo":"Flow-Launcher/Flow.Launcher","slug":"getuiobjectof-failed","errorCode":null,"errorMessage":"GetUIObjectOf failed","messagePattern":"GetUIObjectOf failed","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs","lineNumber":198,"sourceCode":"        IShellFolder shellFolder = null;\n\n        try\n        {\n            malloc = GetMalloc();\n            var hr = SHParseDisplayName(fileName, IntPtr.Zero, out var pidl, 0, out _);\n            if (hr != 0) throw new Exception(\"SHParseDisplayName failed\");\n\n            originalPidl = pidl;\n\n            var guid = typeof(IShellFolder).GUID;\n            hr = SHBindToParent(pidl, guid, out pShellFolder, ref pidl);\n            if (hr != 0) throw new Exception(\"SHBindToParent failed\");\n\n            shellFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(pShellFolder, typeof(IShellFolder));\n            hr = shellFolder.GetUIObjectOf(\n                IntPtr.Zero, 1, new[] { pidl }, typeof(IContextMenu).GUID, IntPtr.Zero, out pContextMenu\n            );\n            if (hr != 0) throw new Exception(\"GetUIObjectOf failed\");\n\n            contextMenu = (IContextMenu)Marshal.GetTypedObjectForIUnknown(pContextMenu, typeof(IContextMenu));\n\n            hMenu = CreatePopupMenu();\n            contextMenu.QueryContextMenu(hMenu, 0, ContextMenuStartId, ContextMenuEndId, (uint)ContextMenuFlags.Explore);\n\n            var directory = Path.GetDirectoryName(fileName);\n            var invokeCommandInfo = new CMINVOKECOMMANDINFO\n            {\n                cbSize = (uint)Marshal.SizeOf(typeof(CMINVOKECOMMANDINFO)),\n                fMask = (uint)ContextMenuInvokeCommandFlags.Unicode,\n                hwnd = IntPtr.Zero,\n                lpVerb = (IntPtr)(menuItemId - ContextMenuStartId),\n                lpParameters = null,\n                lpDirectory = null,\n                nShow = 1,\n                hIcon = IntPtr.Zero,\n            };","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/Flow-Launcher/Flow.Launcher/blob/7fc63b07bbaa10a0f0b2601487913fcba9ed24b0/Plugins/Flow.Launcher.Plugin.Explorer/Helper/ShellContextMenuDisplayHelper.cs#L180-L216","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Preserve the HRESULT: throw new COMException(\"GetUIObjectOf failed\", hr).","Fall back to a default Flow Launcher action menu when GetUIObjectOf fails, rather than aborting the whole operation.","Try the SHELL namespace IExplorerCommand interface or SHCreateDefaultContextMenu as an alternative when IContextMenu is refused.","Verify the file is hydrated/available (e.g. File.Exists, attributes check) before requesting the menu."],"exampleFix":"// before\nhr = shellFolder.GetUIObjectOf(IntPtr.Zero, 1, new[] { pidl }, typeof(IContextMenu).GUID, IntPtr.Zero, out pContextMenu);\nif (hr != 0) throw new Exception(\"GetUIObjectOf failed\");\n\n// after\nhr = shellFolder.GetUIObjectOf(IntPtr.Zero, 1, new[] { pidl }, typeof(IContextMenu).GUID, IntPtr.Zero, out pContextMenu);\nif (hr != 0) throw new COMException(\"GetUIObjectOf failed\", hr);","handlingStrategy":"fallback","validationCode":"// No reliable pre-check; verify hydration/availability as a proxy.\nvar attrs = File.GetAttributes(fileName);\nif ((attrs & FileAttributes.Offline) != 0) logger.Warn($\"Item is offline: {fileName}\");","typeGuard":"static bool LooksHydrated(string path) { try { return !File.GetAttributes(path).HasFlag(FileAttributes.Offline); } catch { return false; } }","tryCatchPattern":"try { ShellContextMenuDisplayHelper.ExecuteContextMenuItem(fileName, menuItemId); }\ncatch (Exception ex) when (ex.Message == \"GetUIObjectOf failed\")\n{\n    ShowFallbackMenu(fileName); // built-in Open / Copy path\n}","preventionTips":["Hydrate online-only files before requesting their context menu.","Provide a built-in fallback menu for items where the Shell refuses IContextMenu.","Run Flow Launcher and shell extensions at the same integrity level.","Disable crashed shell extensions via ShellExView to isolate the cause."],"tags":["win32","shell-com","context-menu","ishellfolder","csharp"],"backgroundTag":null,"analyzedSha":"7fc63b07bbaa10a0f0b2601487913fcba9ed24b0","analyzedAt":"2026-08-13T14:54:20.914Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}