{"record":{"id":"ee075f256b651808","repo":"d2phap/ImageGlass","slug":"webpinitdecoderconfig-failed-wrong-version","errorCode":null,"errorMessage":"WebPInitDecoderConfig failed. Wrong version?","messagePattern":"WebPInitDecoderConfig failed\\. Wrong version\\?","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"v9/Components/ImageGlass.WebP/WebPWrapper.cs","lineNumber":141,"sourceCode":"        }\n    }\n\n    /// <summary>Decode a WebP image</summary>\n    /// <param name=\"rawWebP\">the data to uncompress</param>\n    /// <param name=\"options\">Options for advanced decode</param>\n    /// <returns>Bitmap with the WebP image</returns>\n    public static Bitmap Decode(byte[] rawWebP, WebPDecoderOptions options, PixelFormat pixelFormat = PixelFormat.DontCare)\n    {\n        GCHandle pinnedWebP = GCHandle.Alloc(rawWebP, GCHandleType.Pinned);\n        Bitmap? bmp = null;\n        BitmapData? bmpData = null;\n        VP8StatusCode result;\n        try\n        {\n            WebPDecoderConfig config = new WebPDecoderConfig();\n            if (LibWebp.WebPInitDecoderConfig(ref config) == 0)\n            {\n                throw new Exception(\"WebPInitDecoderConfig failed. Wrong version?\");\n            }\n            // Read the .webp input file information\n            IntPtr ptrRawWebP = pinnedWebP.AddrOfPinnedObject();\n            int height;\n            int width;\n            if (options.use_scaling == 0)\n            {\n                result = LibWebp.WebPGetFeatures(ptrRawWebP, rawWebP.Length, ref config.input);\n                if (result != VP8StatusCode.VP8_STATUS_OK)\n                    throw new Exception(\"Failed WebPGetFeatures with error \" + result);\n\n                //Test cropping values\n                if (options.use_cropping == 1)\n                {\n                    if (options.crop_left + options.crop_width > config.input.Width || options.crop_top + options.crop_height > config.input.Height)\n                        throw new Exception(\"Crop options exceeded WebP image dimensions\");\n                    width = options.crop_width;\n                    height = options.crop_height;","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/d2phap/ImageGlass/blob/4a3c4feceffc5a8bb5e56ba836509634aaae47a9/v9/Components/ImageGlass.WebP/WebPWrapper.cs#L123-L159","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Verify libwebp.dll (or libwebp.so/.dylib) is present in the runtime path for the process architecture (x64/ARM64).","Confirm the process bitness matches the native library bitness; set Platform=x64 (or ARM64) explicitly.","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."],"exampleFix":"// before: relies on whatever libwebp is found\nvar bmp = WebPWrapper.Decode(rawWebP, options);\n\n// after: fail fast at startup if the native ABI is wrong\nif (LibWebp.WebPGetDecoderVersion() == 0)\n    throw new InvalidOperationException(\"libwebp native library not loaded or wrong version.\");\nvar bmp = WebPWrapper.Decode(rawWebP, options);","handlingStrategy":"validation","validationCode":"// Fail fast if the libwebp ABI is mismatched / native lib missing.\nif (LibWebp.WebPGetDecoderVersion() == 0)\n    throw new DllNotFoundException(\"libwebp native library not loaded or wrong ABI version.\");","typeGuard":null,"tryCatchPattern":"try { bmp = WebPWrapper.Decode(rawWebP, options); }\ncatch (Exception ex) when (ex.Message.Contains(\"WebPInitDecoderConfig failed\"))\n{ /* ABI mismatch — reinstall matching libwebp native binary */ }","preventionTips":["Always ship the libwebp native binary paired with the wrapper version.","Verify the native lib is present for the process bitness/architecture.","Run an ABI smoke test at startup to surface a clear error."],"tags":["webp","libwebp","native-interop","version-mismatch","p-invoke","imageglass","v9"],"backgroundTag":null,"analyzedSha":"4a3c4feceffc5a8bb5e56ba836509634aaae47a9","analyzedAt":"2026-08-13T16:58:15.523Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}