{"record":{"id":"8a11ff5fb9e3ef7c","repo":"dotnet/wpf","slug":"image-metadatanotsupported","errorCode":null,"errorMessage":"Image_MetadataNotSupported","messagePattern":"Image_MetadataNotSupported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapImage.cs","lineNumber":140,"sourceCode":"        /// Returns if the BitmapFrame is downloading content\n        /// </summary>\n        public override bool IsDownloading\n        {\n            get\n            {\n                ReadPreamble();\n                return _isDownloading;\n            }\n        }\n\n        /// <summary>\n        /// Get the Metadata of the bitmap\n        /// </summary>\n        public override ImageMetadata Metadata\n        {\n            get\n            {\n                throw new System.NotSupportedException(SR.Image_MetadataNotSupported);\n            }\n        }\n\n\n        #endregion\n\n        #region ToString\n\n        /// <summary>\n        /// Can serialze \"this\" to a string\n        /// </summary>\n        internal override bool CanSerializeToString()\n        {\n            ReadPreamble();\n\n            return (\n                // UriSource not null\n                UriSource != null &&","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapImage.cs#L122-L158","documentation":"BitmapImage overrides Metadata with a getter that always throws NotSupportedException with SR.Image_MetadataNotSupported. BitmapImage does not expose decoder metadata by design; to read metadata you must use BitmapFrame/BitmapDecoder instead.","triggerScenarios":"Reading the Metadata property on any BitmapImage instance, e.g. ((BitmapImage)image.Source).Metadata.","commonSituations":"Code that reads ImageSource.Metadata generically after loading via BitmapImage; porting code from BitmapFrame to BitmapImage and expecting metadata access to still work.","solutions":["Get metadata from the decoder instead: BitmapDecoder.Create(image.UriSource, ...).Frames[0].Metadata.","Cast/check for BitmapFrame first: if (source is BitmapFrame f) use f.Metadata.","Wrap the access in try/catch (NotSupportedException) when metadata is optional.","Restructure loading code to keep a reference to the BitmapDecoder/BitmapFrame rather than only the BitmapImage."],"exampleFix":"// before\nvar meta = ((BitmapImage)img.Source).Metadata; // NotSupported\n\n// after\nvar dec = BitmapDecoder.Create(((BitmapImage)img.Source).UriSource, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);\nvar meta = dec.Frames[0].Metadata;","handlingStrategy":"try-catch","validationCode":"if (source is BitmapImage) { /* metadata not available; resolve via BitmapDecoder */ }","typeGuard":"bool hasMetadata(ImageSource src) => src is BitmapFrame or BitmapDecoder;","tryCatchPattern":"try { var meta = bitmapImage.Metadata; }\ncatch (NotSupportedException) { var meta = BitmapDecoder.Create(bitmapImage.UriSource, BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames[0].Metadata; }","preventionTips":["Never read Metadata from BitmapImage; go through BitmapDecoder/BitmapFrame.","Keep decoder references alive alongside your Image controls.","Document in imaging helpers that BitmapImage has no metadata."],"tags":["wpf","imaging","metadata","not-supported"],"backgroundTag":"operation-not-supported","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}