{"record":{"id":"825884f7481b506c","repo":"dotnet/wpf","slug":"sr-image-nodecodeframes","errorCode":null,"errorMessage":"SR.Image_NoDecodeFrames","messagePattern":"SR\\.Image_NoDecodeFrames","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapImage.cs","lineNumber":381,"sourceCode":"                    decoder.DownloadCompleted += OnDownloadCompleted;\n                    decoder.DownloadFailed += OnDownloadFailed;\n                }\n                else\n                {\n                    Debug.Assert(decoder.SyncObject != null);\n                }\n            }\n            else\n            {\n                // We already had a decoder, meaning we were downloading\n                Debug.Assert(!_decoder.IsDownloading);\n                decoder = _decoder;\n                _decoder = null;\n            }\n\n            if (decoder.Frames.Count == 0)\n            {\n                throw new System.ArgumentException(SR.Image_NoDecodeFrames);\n            }\n\n            BitmapFrame frame = decoder.Frames[0];\n            BitmapSource source = frame;\n\n            Int32Rect sourceRect = SourceRect;\n\n            if (sourceRect.X == 0 && sourceRect.Y == 0 &&\n                sourceRect.Width == source.PixelWidth &&\n                sourceRect.Height == source.PixelHeight)\n            {\n                sourceRect = Int32Rect.Empty;\n            }\n\n            if (!sourceRect.IsEmpty)\n            {\n                CroppedBitmap croppedSource = new CroppedBitmap();\n                croppedSource.BeginInit();","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapImage.cs#L363-L399","documentation":"FinalizeCreation decodes the downloaded/opened bitmap into a frame. WPF throws ArgumentException with SR.Image_NoDecodeFrames when the decoder produced zero frames, meaning the image source yielded no decodable image data. The bitmap cannot be displayed, so creation is aborted.","triggerScenarios":"Calling EndInit() on a BitmapImage (or the download completing via OnDownloadCompleted) when the underlying stream/URI contains no decodable image frames — e.g. a zero-byte file, truncated download, HTML error page saved as .png, or a corrupt/unsupported image format.","commonSituations":"Server returns a 404/500 HTML page where an image was expected; network interrupted mid-download; file corrupted on disk; codec not installed for the format (e.g. HD Photo/WDP); empty placeholder files generated by a build or upload pipeline.","solutions":["Verify the image source is a complete, valid image file (open it in an image viewer or check magic bytes) before assigning it to BitmapImage","Check the HTTP response status and content type before saving/downloading to a stream used by BitmapImage","Wrap EndInit in try/catch for ArgumentException and fall back to a placeholder image or retry the download","Confirm the required WIC codec for the format is installed on the machine"],"exampleFix":"// before\nvar bmp = new BitmapImage();\nbmp.BeginInit();\nbmp.UriSource = new Uri(url);\nbmp.EndInit(); // throws if decoder yields 0 frames\n// after\nvar bmp = new BitmapImage();\nbmp.BeginInit();\nbmp.UriSource = new Uri(url);\ntry { bmp.EndInit(); }\ncatch (ArgumentException) { bmp = CreatePlaceholderImage(); }","handlingStrategy":"try-catch","validationCode":"// validate before decode\nstatic bool LooksLikeImage(byte[] data) =>\n    data != null && data.Length > 0 &&\n    (data.Length >= 8 && data[0]==0x89 && data[1]==(byte)'P' ||  // PNG\n     data[0]==0xFF && data[1]==0xD8 ||                            // JPEG\n     data[0]==(byte)'G' && data[1]==(byte)'I' && data[2]==(byte)'F'); // GIF","typeGuard":null,"tryCatchPattern":"try { img.EndInit(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"NoDecodeFrames\") || ex.ParamName == null)\n{\n    logger.LogWarning(ex, \"Image decoded to 0 frames: {Uri}\", uri);\n    imageControl.Source = CreatePlaceholder();\n}","preventionTips":["Check HTTP status and Content-Type before feeding a downloaded stream to BitmapImage","Use BitmapCacheOption.OnLoad with a verified stream to fail early and release the source","Validate file magic bytes before binding the image","Keep a placeholder image fallback for user-supplied or remote sources"],"tags":["wpf","bitmapimage","image-decoding","corrupt-data"],"backgroundTag":"empty-result-set","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"}