dotnet/wpf · error · ArgumentException
SR.Image_NoDecodeFrames
Error message
SR.Image_NoDecodeFrames
What it means
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.
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
Example fix
// before
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(url);
bmp.EndInit(); // throws if decoder yields 0 frames
// after
var bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(url);
try { bmp.EndInit(); }
catch (ArgumentException) { bmp = CreatePlaceholderImage(); } Defensive patterns
Strategy: try-catch
Validate before calling
// validate before decode
static bool LooksLikeImage(byte[] data) =>
data != null && data.Length > 0 &&
(data.Length >= 8 && data[0]==0x89 && data[1]==(byte)'P' || // PNG
data[0]==0xFF && data[1]==0xD8 || // JPEG
data[0]==(byte)'G' && data[1]==(byte)'I' && data[2]==(byte)'F'); // GIF Try / catch
try { img.EndInit(); }
catch (ArgumentException ex) when (ex.Message.Contains("NoDecodeFrames") || ex.ParamName == null)
{
logger.LogWarning(ex, "Image decoded to 0 frames: {Uri}", uri);
imageControl.Source = CreatePlaceholder();
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- Image_NeitherArgument (UriSource, StreamSource)
- InvalidDataInISF
- SR.Format(SR.RequiredAttributeMissing…
- SR.Image_InitializationIncomplete
- SR.Image_NotInitialized
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/825884f7481b506c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapImage.cs:381
decoder.DownloadCompleted += OnDownloadCompleted;
decoder.DownloadFailed += OnDownloadFailed;
}
else
{
Debug.Assert(decoder.SyncObject != null);
}
}
else
{
// We already had a decoder, meaning we were downloading
Debug.Assert(!_decoder.IsDownloading);
decoder = _decoder;
_decoder = null;
}
if (decoder.Frames.Count == 0)
{
throw new System.ArgumentException(SR.Image_NoDecodeFrames);
}
BitmapFrame frame = decoder.Frames[0];
BitmapSource source = frame;
Int32Rect sourceRect = SourceRect;
if (sourceRect.X == 0 && sourceRect.Y == 0 &&
sourceRect.Width == source.PixelWidth &&
sourceRect.Height == source.PixelHeight)
{
sourceRect = Int32Rect.Empty;
}
if (!sourceRect.IsEmpty)
{
CroppedBitmap croppedSource = new CroppedBitmap();
croppedSource.BeginInit();View on GitHub (pinned to 81131a70a4)