{"record":{"id":"f147987c5c2bf543","repo":"dotnet/wpf","slug":"image-nodecodeframes-stream","errorCode":null,"errorMessage":"Image_NoDecodeFrames (stream)","messagePattern":"Image_NoDecodeFrames \\(stream\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrame.cs","lineNumber":80,"sourceCode":"                {\n                    throw new System.ArgumentException(SR.Image_NoDecodeFrames, nameof(uri));\n                }\n\n                return decoder.Frames[0];\n            }\n            else\n            {\n                Debug.Assert((stream != null), \"Both stream and uri are null\");\n\n                BitmapDecoder decoder = BitmapDecoder.Create(\n                    stream,\n                    createOptions,\n                    cacheOption\n                    );\n\n                if (decoder.Frames.Count == 0)\n                {\n                    throw new System.ArgumentException(SR.Image_NoDecodeFrames, nameof(stream));\n                }\n\n                return decoder.Frames[0];\n            }\n        }\n\n        /// <summary>\n        /// Create a BitmapFrame from a Uri using BitmapCreateOptions.None and\n        /// BitmapCacheOption.Default\n        /// </summary>\n        /// <param name=\"bitmapUri\">Uri of the Bitmap</param>\n        public static BitmapFrame Create(\n            Uri bitmapUri\n            )\n        {\n            return Create(bitmapUri, null);\n        }\n        ","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrame.cs#L62-L98","documentation":"BitmapFrame.Create(Stream, ...) throws ArgumentException with SR.Image_NoDecodeFrames when decoding the supplied stream produces a decoder with zero frames. The stream content either is not decodable image data or ends before any frame is present.","triggerScenarios":"BitmapFrame.Create(stream) or Create(stream, createOptions, cacheOption) with a stream whose decoded Frames.Count == 0 (empty stream, wrong format, truncated data).","commonSituations":"Passing an HTTP response stream that contains an error body instead of image bytes; MemoryStream positioned at End or zero-length; uploading a corrupted file.","solutions":["Ensure the stream is positioned at 0 (stream.Position = 0) and is non-empty before calling Create.","Validate the stream's magic bytes (PNG \\x89PNG, JPEG FFD8, etc.) before decoding.","Wrap the stream in a BitmapDecoder and check Frames.Count before extracting a frame.","Use BitmapCacheOption.OnLoad so the entire stream is read and buffered at decode time."],"exampleFix":"// before\nvar frame = BitmapFrame.Create(responseStream);\n\n// after\nresponseStream.Position = 0;\nif (responseStream.Length == 0) throw new InvalidDataException(\"Empty image stream\");\nvar dec = BitmapDecoder.Create(responseStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);\nvar frame = dec.Frames.Count > 0 ? dec.Frames[0] : null;","handlingStrategy":"validation","validationCode":"if (stream == null || !stream.CanRead) throw new ArgumentException(\"stream\");\nstream.Position = 0;\nif (stream.Length == 0) throw new InvalidDataException(\"Empty image stream\");","typeGuard":"bool isDecodableStream(Stream s) { try { s.Position = 0; return BitmapDecoder.Create(s, BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.Count > 0; } catch { return false; } }","tryCatchPattern":"try { frame = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); }\ncatch (ArgumentException ex) when (ex.ParamName == \"stream\") { /* handle undecodable stream */ }","preventionTips":["Always reset stream.Position to 0 before decoding.","Check HTTP status/content-type before treating a response body as an image.","Use BitmapCacheOption.OnLoad to fully consume the stream."],"tags":["wpf","imaging","decode","stream"],"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-22T01:17:13.364Z"}