Flow-Launcher/Flow.Launcher · warning · InvalidOperationException

Failed to get IShellItemImageFactory

Error message

Failed to get IShellItemImageFactory

What it means

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.

Source

Thrown at Flow.Launcher.Infrastructure/Image/ThumbnailReader.cs:101

        /// <param name="fileName">Path to the file to thumbnail.</param>
        /// <param name="width">Requested thumbnail width in pixels.</param>
        /// <param name="height">Requested thumbnail height in pixels.</param>
        /// <param name="options">Thumbnail request flags that control behavior (e.g., ThumbnailOnly, IconOnly).</param>
        /// <returns>An HBITMAP handle containing the image. Caller must free the handle when finished.</returns>
        /// <exception cref="COMException">If creating the shell item fails (HRESULT returned by SHCreateItemFromParsingName).</exception>
        /// <exception cref="InvalidOperationException">If the shell item does not expose IShellItemImageFactory or if an unexpected error occurs while obtaining the image.</exception>
        private static unsafe HBITMAP GetHBitmap(string fileName, int width, int height, ThumbnailOptions options)
        {
            var retCode = PInvoke.SHCreateItemFromParsingName<IShellItem>(fileName, null, out var shellItem);

            if (retCode != HRESULT.S_OK)
                throw Marshal.GetExceptionForHR(retCode);

            if (shellItem is not IShellItemImageFactory imageFactory)
            {
                Marshal.ReleaseComObject(shellItem);
                shellItem = null;
                throw new InvalidOperationException("Failed to get IShellItemImageFactory");
            }

            SIZE size = new SIZE
            {
                cx = width,
                cy = height
            };

            HBITMAP hBitmap = default;
            try
            {
                try
                {
                    imageFactory.GetImage(size, (SIIGBF)options, &hBitmap);
                }
                catch (COMException ex) when (options == ThumbnailOptions.ThumbnailOnly &&
                    (ex.HResult == S_PATHNOTFOUND || ex.HResult == S_EXTRACTIONFAILED))
                {

View on GitHub (pinned to 7fc63b07bb)

Solutions

  1. Catch InvalidOperationException and fall back to a default/type-icon via SHGetFileInfo instead.
  2. Pre-filter inputs to real, existing filesystem files before calling the thumbnail API.
  3. If the issue persists for one file type, re-associate that extension with an application to restore its icon handler.
  4. Run 'sfc /scannow' if shell icon cache/registry is suspected corrupted.

Example fix

// before
if (shellItem is not IShellItemImageFactory imageFactory)
    throw new InvalidOperationException("Failed to get IShellItemImageFactory");

// after — degrade gracefully to the file-type icon
if (shellItem is not IShellItemImageFactory imageFactory)
{
    Marshal.ReleaseComObject(shellItem);
    return GetDefaultIconFallback(fileName, width, height);
}
Defensive patterns

Strategy: fallback

Validate before calling

if (!File.Exists(fileName)) return defaultIcon;
// optionally pre-check the extension has a registered thumbnail provider

Type guard

null

Try / catch

try { return ThumbnailReader.GetThumbnail(fileName, w, h, options); }
catch (InvalidOperationException ex) when (ex.Message.Contains("IShellItemImageFactory"))
{ return IconExtractor.GetFileIcon(fileName, IconSize.Small); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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