ShareX/ShareX · error · InvalidOperationException

SkiaSharp returned no bitmap.

Error message

SkiaSharp returned no bitmap.

What it means

EditorWindow.LoadImageInternal opens the file and calls SKBitmap.Decode; if decode returns null (no exception, just no bitmap) it throws InvalidOperationException. The surrounding try/catch reports it via EditorServices rather than crashing the window.

Source

Thrown at ShareX.ImageEditor/Presentation/Views/EditorWindow.axaml.cs:184

            // If window not loaded yet, defer image loading
            if (!IsLoaded)
            {
                _pendingFilePath = filePath;
                return;
            }

            LoadImageInternal(filePath);
        }

        private void LoadImageInternal(string filePath)
        {
            try
            {
                using var stream = File.OpenRead(filePath);
                SKBitmap? bitmap = SKBitmap.Decode(stream);
                if (bitmap == null)
                {
                    throw new InvalidOperationException("SkiaSharp returned no bitmap.");
                }

                _viewModel.UpdatePreview(bitmap);
                _viewModel.ImageFilePath = filePath;
                _viewModel.IsDirty = false;
            }
            catch (Exception ex)
            {
                EditorServices.ReportError(nameof(EditorWindow), $"Failed to load image file '{filePath}'.", ex);
            }
        }

        /// <summary>
        /// Loads an image from a stream.
        /// </summary>
        /// <param name="stream">Stream containing image data.</param>
        public void LoadImage(Stream stream)
        {

View on GitHub (pinned to f7d4b6bfbf)

Solutions

  1. Confirm the file is a supported raster image (PNG/JPEG/BMP/GIF/WebP) and opens elsewhere.
  2. Re-save/convert the source to PNG and retry loading.
  3. Check EditorServices logs for the reported error to confirm it is the null-bitmap path.
  4. Bundle/upgrade SkiaSharp native binaries so the needed codec is present.
Defensive patterns

Strategy: try-catch

Validate before calling

using var fs = File.OpenRead(filePath);
using var probe = SKBitmap.Decode(fs);
if (probe == null) { /* warn user, do not call LoadImageInternal */ }

Try / catch

try { LoadImageInternal(filePath); }
catch (Exception ex) { EditorServices.ReportError(nameof(EditorWindow), $"Failed to load '{filePath}'.", ex); }

Prevention

When it happens

Trigger: Loading an image file into the editor whose format Skia cannot rasterize (returns null), e.g. unsupported format, malformed header, or an empty/placeholder file.

Common situations: User drags in a non-raster file (SVG, PDF, EXE renamed .png); truncated download; codec for the format absent from the SkiaSharp native bundle.

Related errors


AI-assisted analysis of ShareX/ShareX@f7d4b6bfbf (2026-08-13). Data as JSON: /api/errors/d689d33198fc2d61. Report an issue: GitHub.