dotnet/wpf · error · ArgumentException
Invalid ISF data
Error message
Invalid ISF data
What it means
LoadStrokeIds decodes the stroke-ID count from the raw ISF stream and throws ArgumentException("Invalid ISF data") when the encoded count occupies more bytes than remain (cb > cbTotal). This is a structural validation: the ID-count field cannot exceed the remaining payload, so the data is malformed.
Solutions
- Verify the ISF payload is complete and uncorrupted before loading
- Re-save the ink data from the original application
- Catch ArgumentException around StrokeCollection construction
- Check that any ISF-in-GIF extraction logic reads the correct byte range
Example fix
// before
var strokes = new StrokeCollection(gifStream);
// after
try { var strokes = new StrokeCollection(gifStream); }
catch (ArgumentException ex) { if (ex.Message.Contains("Invalid ISF")) { /* handle corrupt ink */ } } Defensive patterns
Strategy: validation
Validate before calling
// verify the stream is a complete ISF/GIF payload before construction
bool HasValidHeader(Stream s) {
var b = new byte[8]; int n = s.Read(b,0,8); s.Position = 0;
return n == 8 && (b[0]==0x89 && b[1]==(byte)'P' || b[0]==(byte)'G');
} Try / catch
try { strokes = new StrokeCollection(stream); }
catch (ArgumentException ex) when (ex.ParamName == "stream") { HandleCorruptInk(); } Prevention
- Extract ISF from GIF containers using exact documented offsets
- Validate payload integrity before decode
- Re-save corrupted ink from the original application
When it happens
Trigger: DecodeRawISF on a stream whose stroke-ID block claims a byte length larger than the remaining data, typically via DecodeRawISF/DecodeISF triggered by new StrokeCollection(Stream).
Common situations: Truncated or corrupted ISF payloads, offsets computed incorrectly when embedding ISF in GIF, ink data produced by incompatible writers.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- invalid huffman encoded data
- Invalid size specified
- InvalidDataInISF
- InvalidDrawingAttributesWidth
- Buffer range is smaller than expected expected size
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1ddd5f88354a2422.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs:208
#region Private Methods
/// <summary>
/// Loads the strokeIds from the stream, we need to do this to decrement the count of bytes
/// </summary>
internal uint LoadStrokeIds(Stream isfStream, uint cbSize)
{
if (0 == cbSize)
return 0;
uint cb;
uint cbTotal = cbSize;
// First decode the no of ids
uint count;
cb = SerializationHelper.Decode(isfStream, out count);
if (cb > cbTotal)
throw new ArgumentException(ISFDebugMessage("Invalid ISF data"), nameof(isfStream));
cbTotal -= cb;
if (0 == count)
return (cbSize - cbTotal);
cb = cbTotal;
byte[] inputdata = new byte[cb];
// read the stream
uint bytesRead = StrokeCollectionSerializer.ReliableRead(isfStream, inputdata, cb);
if (cb != bytesRead)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Read different size from stream then expected"), nameof(isfStream));
}
cbTotal -= cb;
if (0 != cbTotal)View on GitHub (pinned to 81131a70a4)