{"record":{"id":"05c294fa4b76f276","repo":"dotnet/wpf","slug":"sr-zlibversionerror","errorCode":null,"errorMessage":"SR.ZLibVersionError","messagePattern":"SR\\.ZLibVersionError","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileDeflateTransform.cs","lineNumber":403,"sourceCode":"                    invalidOperation = true; break;\n\n                case ZLibNative.ErrorCode.NeedDictionary:\n                    corruption = true; break;\n\n                case ZLibNative.ErrorCode.StreamError:\n                    corruption = true; break;\n\n                case ZLibNative.ErrorCode.DataError:\n                    corruption = true; break;\n\n                case ZLibNative.ErrorCode.MemError:\n                    throw new OutOfMemoryException();\n\n               case ZLibNative.ErrorCode.BufError:\n                    invalidOperation = true; break;\n\n                case ZLibNative.ErrorCode.VersionError:\n                    throw new InvalidOperationException(SR.Format(SR.ZLibVersionError,\n                        System.Text.Encoding.UTF8.GetString(ZLibVersion, 0, ZLibVersion.Length)));\n\n                default:\n                    {\n                        // ErrorNo\n                        throw new IOException();\n                    }\n            }\n\n            if (invalidOperation)\n                throw new InvalidOperationException();\n\n            if (corruption)\n                throw new FileFormatException(SR.CorruptStream);\n}\n\n        //------------------------------------------------------\n        //","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileDeflateTransform.cs#L385-L421","documentation":"ThrowIfZLibError converts zlib's VersionError (Z_VERSION_ERROR) into an InvalidOperationException carrying SR.ZLibVersionError with the runtime's zlib version string. It is thrown when the linked zlib library's version is incompatible with what ZLibNative expects — an installation/environment problem, not a data problem.","triggerScenarios":"Decompress or Compress invokes zlib and gets Z_VERSION_ERROR: the native zlib on the machine mismatches the version the library was compiled/bound against (e.g. an old or replaced zlib.dll/zlib native image).","commonSituations":"Machines with a stale or vendor-replaced zlib.dll on PATH shadowing the correct one; broken .NET/native runtime installs; deploying WPF apps without the matching native runtime components.","solutions":["Restore the correct zlib native library bundled with the .NET/WPF runtime (reinstall the runtime or redeploy the app).","Check PATH/DLL search order for a rogue zlib.dll shadowing the expected one.","Ensure the app is deployed on a supported OS/runtime version where ZLibNative's expected zlib version is present."],"exampleFix":"// before: shadowed old zlib on PATH\nset PATH=C:\\legacy;%PATH%\n\n// after: let the app's bundled zlib win\nset PATH=C:\\app\\native;%PATH%\n","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { transform.Decompress(stream); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"zlib\")) { ReportEnvironmentProblem(ex); }","preventionTips":["Deploy apps with the .NET/WPF runtime's bundled zlib intact","Audit PATH and app directories for shadowing zlib.dll copies","Pin supported runtime versions in your deployment environment"],"tags":["zlib","version-mismatch","environment","wpf"],"backgroundTag":"version-incompatibility","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}