dotnet/wpf · error · InvalidOperationException
SR.ZLibVersionError
Error message
SR.ZLibVersionError
What it means
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.
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.
Example fix
// before: shadowed old zlib on PATH set PATH=C:\legacy;%PATH% // after: let the app's bundled zlib win set PATH=C:\app\native;%PATH%
Defensive patterns
Strategy: fallback
Try / catch
try { transform.Decompress(stream); } catch (InvalidOperationException ex) when (ex.Message.Contains("zlib")) { ReportEnvironmentProblem(ex); } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- File contains data in format version
- SR.Format(SR.InvalidTransformFeatureName…
- SR.Format(SR.UnknownBamlRecord, recordType)
- SR.ParserAssemblyLoadVersionMismatch
- SR.ParserBamlVersion
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/05c294fa4b76f276.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CompoundFileDeflateTransform.cs:403
invalidOperation = true; break;
case ZLibNative.ErrorCode.NeedDictionary:
corruption = true; break;
case ZLibNative.ErrorCode.StreamError:
corruption = true; break;
case ZLibNative.ErrorCode.DataError:
corruption = true; break;
case ZLibNative.ErrorCode.MemError:
throw new OutOfMemoryException();
case ZLibNative.ErrorCode.BufError:
invalidOperation = true; break;
case ZLibNative.ErrorCode.VersionError:
throw new InvalidOperationException(SR.Format(SR.ZLibVersionError,
System.Text.Encoding.UTF8.GetString(ZLibVersion, 0, ZLibVersion.Length)));
default:
{
// ErrorNo
throw new IOException();
}
}
if (invalidOperation)
throw new InvalidOperationException();
if (corruption)
throw new FileFormatException(SR.CorruptStream);
}
//------------------------------------------------------
//View on GitHub (pinned to 81131a70a4)