dotnet/wpf · error · ArgumentException
Invalid size specified
Error message
Invalid size specified
What it means
Thrown by CustomAttributeSerializer.DecodeAsISF when the tag-embedded payload claims a compressed data size (cb) larger than the total size (cbSize) available. The declared size cannot fit in the provided buffer, indicating corrupt or mismatched ISF data. It surfaces as ArgumentException with paramName cbSize.
Solutions
- Verify you are passing the correct byte range/offset to the decode call — the payload must start at the attribute header.
- Confirm the ISF data is complete and untruncated (compare against expected total size).
- Regenerate the ink data from the original source; the stream is likely corrupt.
- Check for version mismatches between the writer of the data and the WPF version decoding it.
Example fix
// before
customAttr = DecodeAsISF(buffer, 0, stream, 0, guid, ref value);
// after
if (buffer.Length >= expectedAttrSize) customAttr = DecodeAsISF(buffer, 0, stream, 0, guid, ref value);
else throw new InvalidDataException("ISF attribute payload truncated"); Defensive patterns
Strategy: validation
Validate before calling
if (buffer.Length < declaredSize) throw new InvalidDataException($"ISF payload too small: have {buffer.Length}, declared {declaredSize}"); Try / catch
try { attr = DecodeAsISF(buffer, 0, stream, (uint)buffer.Length, tag, out guid); }
catch (ArgumentException ex) { LogCorruption(ex); attr = null; } Prevention
- Pass exact byte ranges/offsets into ISF decoders
- Checksum or size-verify ink files before load
- Regenerate rather than repair corrupt ISF data
When it happens
Trigger: Decoding an ISF custom attribute whose embedded tag block encodes a size exceeding cbSize — typically from corrupted streams, wrong offsets, or mixing data from different ISF payloads.
Common situations: Manually slicing byte arrays out of an ISF stream and passing wrong sub-ranges; loading ink written by a different/older ISF writer with incompatible size encoding; partially downloaded or truncated ink files.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- InvalidDataInISF
- Buffer range is smaller than expected expected size
- Button data length not equal to expected length
- Drawing Attribute tag embedded in ISF stream does not match…
- Empty data to load
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/44801642aa9abaab.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/CustomAttributeSerializer.cs:420
/// <returns>Length of buffer read</returns>
#endif
internal static uint DecodeAsISF(Stream stream, uint cbSize, GuidList guidList, KnownTagCache.KnownTagIndex tag, ref Guid guid, out object data)
{
uint cb, cbRead = 0;
uint cbTotal = cbSize;
if (0 == cbSize)
{
throw new InvalidOperationException(SR.EmptyDataToLoad);
}
if (0 == tag) // no tag is passed, it must be embedded in the data
{
uint uiTag;
cb = SerializationHelper.Decode(stream, out uiTag);
tag = (KnownTagCache.KnownTagIndex)uiTag;
if (cb > cbTotal)
throw new ArgumentException(SR.InvalidSizeSpecified, nameof(cbSize));
cbTotal -= cb;
cbRead += cb;
System.Diagnostics.Debug.Assert(guid == Guid.Empty);
guid = guidList.FindGuid(tag);
}
if (guid == Guid.Empty)
{
throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Custom Attribute tag embedded in ISF stream does not match guid table"), nameof(tag));
}
// Try and find the size
uint size = GuidList.GetDataSizeIfKnownGuid(guid);
if (size > cbTotal)
throw new ArgumentException(SR.InvalidSizeSpecified, nameof(cbSize));
View on GitHub (pinned to 81131a70a4)