dotnet/wpf · error · ArgumentNullException
reader or compressedData was null in compress
Error message
reader or compressedData was null in compress
What it means
This overload of GorillaCodec.Compress (reading from a BitStreamReader) validates that both the reader and the compressedData output list are non-null, throwing ArgumentNullException with this message. As with the array-based overload, null buffers indicate a caller bug rather than corrupt data.
Solutions
- Construct the BitStreamReader from a valid, non-null source stream before calling Compress.
- Initialize compressedData = new List<byte>() before the call.
- Add explicit null checks for both arguments in the calling method.
- Use the high-level StrokeCollection serialization APIs so buffers are managed for you.
Example fix
// before GorillaCodec codec = new GorillaCodec(); codec.Compress(8, reader, GorillaEncodingType.OneByte, count, null); // after List<byte> compressedData = new List<byte>(); codec.Compress(8, reader, GorillaEncodingType.OneByte, count, compressedData);
Defensive patterns
Strategy: validation
Validate before calling
if (reader == null) throw new ArgumentNullException(nameof(reader)); if (compressedData == null) throw new ArgumentNullException(nameof(compressedData));
Type guard
bool CanCompress(BitStreamReader r, List<byte> outBuf) => r != null && outBuf != null;
Try / catch
try { codec.Compress(bitCount, reader, encodingType, units, outBuf); }
catch (ArgumentNullException ex) { log.Error("Missing BitStreamReader/output buffer", ex); throw; } Prevention
- Build the BitStreamReader immediately before use from a verified non-null stream.
- Allocate the output list at the same call site that invokes Compress.
- Guard earlier pipeline steps so a null upstream stream cannot propagate into the codec.
When it happens
Trigger: Calling Compress(bitCount, reader, encodingType, unitsToEncode, compressedData) with reader == null (BitStreamReader never constructed or failed construction) or compressedData == null.
Common situations: Custom encoding pipelines where the BitStreamReader creation was skipped or a stream was null before wrapping; refactors that moved buffer initialization away from the call site.
Related errors
- input or compressed data was null in Compress
- bogus GorillaEncodingType passed to compress
- Transform returned unexpected results
- bogus GorillaEncodingType passed to GetDataFromReader
- bogus GorillaEncodingType passed to Uncompress
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/c9ef046b0043e3b7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs:410
{
writer.Write((uint)input[i], bitCount);
}
}
}
/// <summary>
/// Compress - compresses the byte[] being read by the BitStreamReader into compressed data
/// </summary>
/// <param name="bitCount">the number of bits to use for each element</param>
/// <param name="reader">a reader over the byte[] to compress</param>
/// <param name="encodingType">int, short or byte?</param>
/// <param name="unitsToEncode">number of logical units to encoded</param>
/// <param name="compressedData">output write buffer</param>
internal void Compress(int bitCount, BitStreamReader reader, GorillaEncodingType encodingType, int unitsToEncode, List<byte> compressedData)
{
if (null == reader || null == compressedData)
{
throw new ArgumentNullException(StrokeCollectionSerializer.ISFDebugMessage("reader or compressedData was null in compress"));
}
ArgumentOutOfRangeException.ThrowIfNegative(bitCount);
ArgumentOutOfRangeException.ThrowIfNegative(unitsToEncode);
if (bitCount == 0)
{
//adjust if the bitcount is 0
//(this makes bitCount 32)
switch (encodingType)
{
case GorillaEncodingType.Int:
{
bitCount = Native.BitsPerInt;
break;
}
case GorillaEncodingType.Short:
{
bitCount = Native.BitsPerShort;View on GitHub (pinned to 81131a70a4)