dotnet/wpf · error · ArgumentNullException
input or compressed data was null in Compress
Error message
input or compressed data was null in Compress
What it means
GorillaCodec.Compress validates its inputs: the int[] payload (input) and the List<byte> output (compressedData) must both be non-null, otherwise ArgumentNullException is thrown with this message. Gorilla compression is used internally when serializing stroke packet data to ISF; passing null buffers is a programming error by the caller.
Solutions
- Allocate the output buffer before compressing: compressedData = new List<byte>();
- Ensure input packet array is created and populated (even empty) rather than null.
- Add null checks/guards in the calling code before invoking Compress.
- Prefer the public StrokeCollection.Save API which initializes all buffers for you.
Example fix
// before List<byte> compressedData = null; codec.Compress(8, packetData, 0, dtxf, compressedData); // after List<byte> compressedData = new List<byte>(packetData.Length); codec.Compress(8, packetData, 0, dtxf, compressedData);
Defensive patterns
Strategy: validation
Validate before calling
if (input == null) throw new ArgumentNullException(nameof(input)); if (compressedData == null) throw new ArgumentNullException(nameof(compressedData));
Type guard
bool CanCompress(int[] input, List<byte> outBuf) => input != null && outBuf != null;
Try / catch
try { codec.Compress(bitCount, packets, 0, dtxf, outBuf); }
catch (ArgumentNullException ex) { log.Error("Gorilla compress buffers missing", ex); throw; } Prevention
- Always allocate the output List<byte> before compressing.
- Treat empty arrays as valid; never pass null as a placeholder.
- Initialize codec inputs in one place to avoid scattered nulls.
When it happens
Trigger: Calling Compress(bitCount, input, startInputIndex, dtxf, compressedData) with input == null or compressedData == null — typically in custom code that drives the Gorilla codec directly or a bug in a custom data pipeline that forgot to allocate the output list.
Common situations: Custom ink serialization code reusing GorillaCodec; refactoring that left a list uninitialized before compression; unit tests exercising the codec with placeholder nulls.
Related errors
- reader or compressedData 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/3243e7bd05848c17.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GorillaCodec.cs:362
{
bitCount = (int)_gorIndexMap[index].BitCount;
padCount = (int)_gorIndexMap[index].PadCount;
}
}
/// <summary>
/// Compress - compress the input[] into compressedData
/// </summary>
/// <param name="bitCount">The count of bits needed for all elements</param>
/// <param name="input">input buffer</param>
/// <param name="startInputIndex">offset into the input buffer</param>
/// <param name="dtxf">data transform. can be null</param>
/// <param name="compressedData">The list of bytes to write the compressed input to</param>
internal void Compress(int bitCount, int[] input, int startInputIndex, DeltaDelta dtxf, List<byte> compressedData)
{
if (null == input || null == compressedData)
{
throw new ArgumentNullException(StrokeCollectionSerializer.ISFDebugMessage("input or compressed data was null in Compress"));
}
ArgumentOutOfRangeException.ThrowIfNegative(bitCount);
if (bitCount == 0)
{
//adjust if the bitcount is 0
//(this makes bitCount 32)
bitCount = (int)(Native.SizeOfInt << 3);
}
//have the writer adapt to the List<byte> passed in and write to it
BitStreamWriter writer = new BitStreamWriter(compressedData);
if (null != dtxf)
{
int xfData = 0;
int xfExtra = 0;
for (int i = startInputIndex; i < input.Length; i++)
{View on GitHub (pinned to 81131a70a4)