{"record":{"id":"969072788a25df0c","repo":"Flow-Launcher/Flow.Launcher","slug":"failed-to-get-ishellitemimagefactory","errorCode":null,"errorMessage":"Failed to get IShellItemImageFactory","messagePattern":"Failed to get IShellItemImageFactory","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"Flow.Launcher.Infrastructure/Image/ThumbnailReader.cs","lineNumber":101,"sourceCode":"        /// <param name=\"fileName\">Path to the file to thumbnail.</param>\n        /// <param name=\"width\">Requested thumbnail width in pixels.</param>\n        /// <param name=\"height\">Requested thumbnail height in pixels.</param>\n        /// <param name=\"options\">Thumbnail request flags that control behavior (e.g., ThumbnailOnly, IconOnly).</param>\n        /// <returns>An HBITMAP handle containing the image. Caller must free the handle when finished.</returns>\n        /// <exception cref=\"COMException\">If creating the shell item fails (HRESULT returned by SHCreateItemFromParsingName).</exception>\n        /// <exception cref=\"InvalidOperationException\">If the shell item does not expose IShellItemImageFactory or if an unexpected error occurs while obtaining the image.</exception>\n        private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height, ThumbnailOptions options)\n        {\n            var retCode = PInvoke.SHCreateItemFromParsingName<IShellItem>(fileName, null, out var shellItem);\n\n            if (retCode != HRESULT.S_OK)\n                throw Marshal.GetExceptionForHR(retCode);\n\n            if (shellItem is not IShellItemImageFactory imageFactory)\n            {\n                Marshal.ReleaseComObject(shellItem);\n                shellItem = null;\n                throw new InvalidOperationException(\"Failed to get IShellItemImageFactory\");\n            }\n\n            SIZE size = new SIZE\n            {\n                cx = width,\n                cy = height\n            };\n\n            HBITMAP hBitmap = default;\n            try\n            {\n                try\n                {\n                    imageFactory.GetImage(size, (SIIGBF)options, &hBitmap);\n                }\n                catch (COMException ex) when (options == ThumbnailOptions.ThumbnailOnly &&\n                    (ex.HResult == S_PATHNOTFOUND || ex.HResult == S_EXTRACTIONFAILED))\n                {","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Flow-Launcher/Flow.Launcher/blob/7fc63b07bbaa10a0f0b2601487913fcba9ed24b0/Flow.Launcher.Infrastructure/Image/ThumbnailReader.cs#L83-L119","documentation":"Thrown as InvalidOperationException when SHCreateItemFromParsingName succeeds (S_OK) but the returned IShellItem cannot be cast to IShellItemImageFactory. Not all shell items expose the image-factory interface — only items that the shell considers capable of producing a thumbnail/icon do. The shell item is released before throwing.","triggerScenarios":"The file is a type Windows shell doesn't associate with a thumbnail/icon provider (e.g. a raw stream, a virtual folder, a non-filesystem namespace); the file extension has no associated icon handler or thumbnail provider registered; the item is a compressed/locked resource the shell refuses to image.","commonSituations":"Passing a path to a special/virtual location (Control Panel item, a device); a file type whose default app was uninstalled leaving no icon handler; attempting thumbnails on an archive or locked system file; corrupted file-extension associations in the registry.","solutions":["Catch InvalidOperationException and fall back to a default/type-icon via SHGetFileInfo instead.","Pre-filter inputs to real, existing filesystem files before calling the thumbnail API.","If the issue persists for one file type, re-associate that extension with an application to restore its icon handler.","Run 'sfc /scannow' if shell icon cache/registry is suspected corrupted."],"exampleFix":"// before\nif (shellItem is not IShellItemImageFactory imageFactory)\n    throw new InvalidOperationException(\"Failed to get IShellItemImageFactory\");\n\n// after — degrade gracefully to the file-type icon\nif (shellItem is not IShellItemImageFactory imageFactory)\n{\n    Marshal.ReleaseComObject(shellItem);\n    return GetDefaultIconFallback(fileName, width, height);\n}","handlingStrategy":"fallback","validationCode":"if (!File.Exists(fileName)) return defaultIcon;\n// optionally pre-check the extension has a registered thumbnail provider","typeGuard":"null","tryCatchPattern":"try { return ThumbnailReader.GetThumbnail(fileName, w, h, options); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"IShellItemImageFactory\"))\n{ return IconExtractor.GetFileIcon(fileName, IconSize.Small); }","preventionTips":["Pre-filter to real, existing filesystem files.","Maintain a fallback path using SHGetFileInfo for items lacking the image factory.","Re-associate file extensions whose icon handler was lost.","Avoid passing virtual/special namespace paths to the thumbnail API."],"tags":["image","thumbnail","win32","shell","com"],"backgroundTag":null,"analyzedSha":"7fc63b07bbaa10a0f0b2601487913fcba9ed24b0","analyzedAt":"2026-08-13T14:54:20.914Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}