{"record":{"id":"0c312f211b5ce320","repo":"dotnet/wpf","slug":"image-nodecodeframes-uri","errorCode":null,"errorMessage":"Image_NoDecodeFrames (uri)","messagePattern":"Image_NoDecodeFrames \\(uri\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrame.cs","lineNumber":63,"sourceCode":"        {\n            // Create a decoder and return the first frame\n            if (uri != null)\n            {\n                Debug.Assert((stream == null), \"Both stream and uri are non-null\");\n\n                BitmapDecoder decoder = BitmapDecoder.CreateFromUriOrStream(\n                    baseUri,\n                    uri,\n                    null,\n                    createOptions,\n                    cacheOption,\n                    uriCachePolicy,\n                    true\n                    );\n\n                if (decoder.Frames.Count == 0)\n                {\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                }","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrame.cs#L45-L81","documentation":"BitmapFrame.Create(Uri, ...) internally decodes the image at the URI and throws ArgumentException with SR.Image_NoDecodeFrames when the decoder exposes zero frames. This means the URI resolved to something WIC could decode structurally enough to create a decoder, but no image frames were found (e.g. an empty or corrupt image file).","triggerScenarios":"BitmapFrame.Create(uri) (or the overload with bitmapCreateOptions/cachePolicy) where the downloaded/opened stream yields a decoder whose Frames.Count == 0.","commonSituations":"Pointing at an HTML error page saved as .png, a zero-byte or truncated image file, an unsupported-but-named image format, or a partially downloaded asset.","solutions":["Verify the URI points to a valid, complete image file; open it locally and check bytes/magic header.","Pre-decode with a BitmapDecoder and check decoder.Frames.Count before BitmapFrame.Create.","Use BitmapCacheOption.OnLoad with a local stream to rule out partial-download/pack issues.","Regenerate or re-download the source image asset."],"exampleFix":"// before\nvar frame = BitmapFrame.Create(new Uri(\"images/logo.png\", UriKind.Relative));\n\n// after\nvar dec = BitmapDecoder.Create(new Uri(\"images/logo.png\", UriKind.Relative), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);\nif (dec.Frames.Count == 0) throw new InvalidDataException(\"Image contains no frames\");\nvar frame = dec.Frames[0];","handlingStrategy":"validation","validationCode":"var dec = BitmapDecoder.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);\nif (dec.Frames.Count == 0) throw new InvalidDataException($\"{uri} decoded with 0 frames\");","typeGuard":"bool hasFrames(Uri uri) { try { return BitmapDecoder.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.Count > 0; } catch { return false; } }","tryCatchPattern":"try { frame = BitmapFrame.Create(uri); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"frame\")) { frame = FallbackImage(); }","preventionTips":["Validate image files (magic bytes, non-zero length) before binding URIs.","Cache-verify downloaded assets are complete.","Prefer BitmapDecoder + explicit Frames.Count checks over direct Create."],"tags":["wpf","imaging","decode","empty-frames"],"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"}