d2phap/ImageGlass · critical · Exception

WebPInitDecoderConfig failed. Wrong version?

Error message

WebPInitDecoderConfig failed. Wrong version?

What it means

Thrown in WebPWrapper.Decode when LibWebp.WebPInitDecoderConfig(ref config) returns 0. WebPInitDecoderConfig is the libwebp ABI handshake: it returns 0 when the WEBP_DECODER_ABI_VERSION compiled into the C# wrapper does not match the loaded libwebp.dll, or when the native library failed to load. This is a setup/version mismatch, not a problem with the input bytes — decoding never starts. The same guard appears in GetThumbnailFast and GetThumbnailQuality.

Source

Thrown at v9/Components/ImageGlass.WebP/WebPWrapper.cs:141

        }
    }

    /// <summary>Decode a WebP image</summary>
    /// <param name="rawWebP">the data to uncompress</param>
    /// <param name="options">Options for advanced decode</param>
    /// <returns>Bitmap with the WebP image</returns>
    public static Bitmap Decode(byte[] rawWebP, WebPDecoderOptions options, PixelFormat pixelFormat = PixelFormat.DontCare)
    {
        GCHandle pinnedWebP = GCHandle.Alloc(rawWebP, GCHandleType.Pinned);
        Bitmap? bmp = null;
        BitmapData? bmpData = null;
        VP8StatusCode result;
        try
        {
            WebPDecoderConfig config = new WebPDecoderConfig();
            if (LibWebp.WebPInitDecoderConfig(ref config) == 0)
            {
                throw new Exception("WebPInitDecoderConfig failed. Wrong version?");
            }
            // Read the .webp input file information
            IntPtr ptrRawWebP = pinnedWebP.AddrOfPinnedObject();
            int height;
            int width;
            if (options.use_scaling == 0)
            {
                result = LibWebp.WebPGetFeatures(ptrRawWebP, rawWebP.Length, ref config.input);
                if (result != VP8StatusCode.VP8_STATUS_OK)
                    throw new Exception("Failed WebPGetFeatures with error " + result);

                //Test cropping values
                if (options.use_cropping == 1)
                {
                    if (options.crop_left + options.crop_width > config.input.Width || options.crop_top + options.crop_height > config.input.Height)
                        throw new Exception("Crop options exceeded WebP image dimensions");
                    width = options.crop_width;
                    height = options.crop_height;

View on GitHub (pinned to 4a3c4fecef)

Solutions

  1. Ensure the libwebp native binary shipped matches the ABI version expected by ImageGlass.WebP (WEBP_DECODER_ABI_VERSION); rebuild/restore the NuGet package that provides both.
  2. Verify libwebp.dll (or libwebp.so/.dylib) is present in the runtime path for the process architecture (x64/ARM64).
  3. Confirm the process bitness matches the native library bitness; set Platform=x64 (or ARM64) explicitly.
  4. Run a trivial P/Invoke smoke test (LibWebp.WebPGetDecoderVersion) at startup to fail fast with a clear native-load error instead of at decode time.

Example fix

// before: relies on whatever libwebp is found
var bmp = WebPWrapper.Decode(rawWebP, options);

// after: fail fast at startup if the native ABI is wrong
if (LibWebp.WebPGetDecoderVersion() == 0)
    throw new InvalidOperationException("libwebp native library not loaded or wrong version.");
var bmp = WebPWrapper.Decode(rawWebP, options);
Defensive patterns

Strategy: validation

Validate before calling

// Fail fast if the libwebp ABI is mismatched / native lib missing.
if (LibWebp.WebPGetDecoderVersion() == 0)
    throw new DllNotFoundException("libwebp native library not loaded or wrong ABI version.");

Try / catch

try { bmp = WebPWrapper.Decode(rawWebP, options); }
catch (Exception ex) when (ex.Message.Contains("WebPInitDecoderConfig failed"))
{ /* ABI mismatch — reinstall matching libwebp native binary */ }

Prevention

When it happens

Trigger: Deploying with a libwebp.dll whose ABI version differs from the one the wrapper was built against; the native libwebp.dll missing from the output dir (P/Invoke loads a wrong/default one); bitness mismatch (32-bit libwebp.dll loaded into a 64-bit process); updating the wrapper without updating the native binary or vice-versa.

Common situations: Packaging/ImageGlass build ships mismatched wrapper+native versions; copying the project without the runtimes/ folder; a dependency update pulled a different Magick.NET/libwebp; running under ARM64 with an x64-only libwebp.

Related errors


AI-assisted analysis of d2phap/ImageGlass@4a3c4fecef (2026-08-13). Data as JSON: /api/errors/ee075f256b651808. Report an issue: GitHub.