dotnet/wpf · error · InvalidOperationException

Image_EncoderNoGlobalThumbnail

Error message

Image_EncoderNoGlobalThumbnail

What it means

The BitmapEncoder.Thumbnail setter rejects a thumbnail when the codec does not support a global (container-level) thumbnail (_supportsGlobalThumbnail is false), throwing InvalidOperationException(Image_EncoderNoGlobalThumbnail). Individual frames may still support thumbnails via the frame's encoder.

Solutions

  1. Check codec capability before assigning Thumbnail
  2. Set the thumbnail on the frame-level BitmapFrame/BitmapEncoder where supported instead of globally
  3. Use an encoder with global-thumbnail support (e.g. Tiff, Jpeg)
  4. Drop the thumbnail when targeting unsupported formats

Example fix

// before
encoder.Thumbnail = thumb; // throws for BmpBitmapEncoder
// after
if (encoder.SupportsGlobalThumbnail) { encoder.Thumbnail = thumb; } // or use TiffBitmapEncoder
Defensive patterns

Strategy: type-guard

Validate before calling

if (!supportsGlobalThumbnailFormat(encoder)) Console.WriteLine("Skipping thumbnail; codec lacks global thumbnail support");

Type guard

static bool SupportsGlobalThumbnail(BitmapEncoder e) => e is TiffBitmapEncoder or JpegBitmapEncoder or WmpBitmapEncoder;

Try / catch

try { encoder.Thumbnail = thumb; }
catch (InvalidOperationException) { /* codec has no global thumbnail; ignore or use frame thumbnail */ }

Prevention

When it happens

Trigger: Assigning encoder.Thumbnail = someBitmapSource on an encoder whose container format has no global-thumbnail support (checked in the setter after EnsureBuiltIn and null checks).

Common situations: Encoding formats like Bmp that lack global thumbnails; porting code that sets Thumbnail on all encoders generically; copying a thumbnail from a source container to an incompatible target.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/b7ffcbd7f081259f. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapEncoder.cs:161

        /// </summary>
        public virtual BitmapSource Thumbnail
        {
            get
            {
                VerifyAccess();
                EnsureBuiltIn();
                return _thumbnail;
            }
            set
            {
                VerifyAccess();
                EnsureBuiltIn();

                ArgumentNullException.ThrowIfNull(value);

                if (!_supportsGlobalThumbnail)
                {
                    throw new InvalidOperationException(SR.Image_EncoderNoGlobalThumbnail);
                }

                _thumbnail = value;
            }
        }

        /// <summary>
        /// Set or get the bitmap's global embedded metadata.
        /// </summary>
        public virtual BitmapMetadata Metadata
        {
            get
            {
                VerifyAccess();
                EnsureBuiltIn();
                EnsureMetadata(true);

                return _metadata;

View on GitHub (pinned to 81131a70a4)