dotnet/wpf · error · ArgumentException

Image_NoDecodeFrames (uri)

Error message

Image_NoDecodeFrames (uri)

What it means

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).

Solutions

  1. Verify the URI points to a valid, complete image file; open it locally and check bytes/magic header.
  2. Pre-decode with a BitmapDecoder and check decoder.Frames.Count before BitmapFrame.Create.
  3. Use BitmapCacheOption.OnLoad with a local stream to rule out partial-download/pack issues.
  4. Regenerate or re-download the source image asset.

Example fix

// before
var frame = BitmapFrame.Create(new Uri("images/logo.png", UriKind.Relative));

// after
var dec = BitmapDecoder.Create(new Uri("images/logo.png", UriKind.Relative), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
if (dec.Frames.Count == 0) throw new InvalidDataException("Image contains no frames");
var frame = dec.Frames[0];
Defensive patterns

Strategy: validation

Validate before calling

var dec = BitmapDecoder.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
if (dec.Frames.Count == 0) throw new InvalidDataException($"{uri} decoded with 0 frames");

Type guard

bool hasFrames(Uri uri) { try { return BitmapDecoder.Create(uri, BitmapCreateOptions.None, BitmapCacheOption.OnLoad).Frames.Count > 0; } catch { return false; } }

Try / catch

try { frame = BitmapFrame.Create(uri); }
catch (ArgumentException ex) when (ex.Message.Contains("frame")) { frame = FallbackImage(); }

Prevention

When it happens

Trigger: BitmapFrame.Create(uri) (or the overload with bitmapCreateOptions/cachePolicy) where the downloaded/opened stream yields a decoder whose Frames.Count == 0.

Common situations: 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.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/0c312f211b5ce320. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapFrame.cs:63

        {
            // Create a decoder and return the first frame
            if (uri != null)
            {
                Debug.Assert((stream == null), "Both stream and uri are non-null");

                BitmapDecoder decoder = BitmapDecoder.CreateFromUriOrStream(
                    baseUri,
                    uri,
                    null,
                    createOptions,
                    cacheOption,
                    uriCachePolicy,
                    true
                    );

                if (decoder.Frames.Count == 0)
                {
                    throw new System.ArgumentException(SR.Image_NoDecodeFrames, nameof(uri));
                }

                return decoder.Frames[0];
            }
            else
            {
                Debug.Assert((stream != null), "Both stream and uri are null");

                BitmapDecoder decoder = BitmapDecoder.Create(
                    stream,
                    createOptions,
                    cacheOption
                    );

                if (decoder.Frames.Count == 0)
                {
                    throw new System.ArgumentException(SR.Image_NoDecodeFrames, nameof(stream));
                }

View on GitHub (pinned to 81131a70a4)