{"record":{"id":"b7ffcbd7f081259f","repo":"dotnet/wpf","slug":"image-encodernoglobalthumbnail","errorCode":null,"errorMessage":"Image_EncoderNoGlobalThumbnail","messagePattern":"Image_EncoderNoGlobalThumbnail","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapEncoder.cs","lineNumber":161,"sourceCode":"        /// </summary>\n        public virtual BitmapSource Thumbnail\n        {\n            get\n            {\n                VerifyAccess();\n                EnsureBuiltIn();\n                return _thumbnail;\n            }\n            set\n            {\n                VerifyAccess();\n                EnsureBuiltIn();\n\n                ArgumentNullException.ThrowIfNull(value);\n\n                if (!_supportsGlobalThumbnail)\n                {\n                    throw new InvalidOperationException(SR.Image_EncoderNoGlobalThumbnail);\n                }\n\n                _thumbnail = value;\n            }\n        }\n\n        /// <summary>\n        /// Set or get the bitmap's global embedded metadata.\n        /// </summary>\n        public virtual BitmapMetadata Metadata\n        {\n            get\n            {\n                VerifyAccess();\n                EnsureBuiltIn();\n                EnsureMetadata(true);\n\n                return _metadata;","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapEncoder.cs#L143-L179","documentation":"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.","triggerScenarios":"Assigning encoder.Thumbnail = someBitmapSource on an encoder whose container format has no global-thumbnail support (checked in the setter after EnsureBuiltIn and null checks).","commonSituations":"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.","solutions":["Check codec capability before assigning Thumbnail","Set the thumbnail on the frame-level BitmapFrame/BitmapEncoder where supported instead of globally","Use an encoder with global-thumbnail support (e.g. Tiff, Jpeg)","Drop the thumbnail when targeting unsupported formats"],"exampleFix":"// before\nencoder.Thumbnail = thumb; // throws for BmpBitmapEncoder\n// after\nif (encoder.SupportsGlobalThumbnail) { encoder.Thumbnail = thumb; } // or use TiffBitmapEncoder","handlingStrategy":"type-guard","validationCode":"if (!supportsGlobalThumbnailFormat(encoder)) Console.WriteLine(\"Skipping thumbnail; codec lacks global thumbnail support\");","typeGuard":"static bool SupportsGlobalThumbnail(BitmapEncoder e) => e is TiffBitmapEncoder or JpegBitmapEncoder or WmpBitmapEncoder;","tryCatchPattern":"try { encoder.Thumbnail = thumb; }\ncatch (InvalidOperationException) { /* codec has no global thumbnail; ignore or use frame thumbnail */ }","preventionTips":["Assign thumbnails only on codecs known to support global thumbnails","Prefer frame-level thumbnails where supported","Centralize encoder property assignment behind capability-checked helpers","Test each target format in CI"],"tags":["wpf","thumbnail","invalid-operation","imaging"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}