dotnet/wpf · error · ArgumentException

Invalid PenTip value found in ISF stream

Error message

Invalid PenTip value found in ISF stream

What it means

When the decoded guid is KnownIds.PenTip, DecodeAsISF reads the raw uint and casts it to PenTip. If the value is not a defined PenTip member (checked via PenTipHelper.IsDefined), the stream is deemed invalid and ArgumentException is thrown. This guards enum integrity when reading ISF.

Solutions

  1. Upgrade to a WPF/.NET version that defines the PenTip value in the stream
  2. Validate/repair the ISF source; re-save from the original application
  3. Catch the exception and fall back to default PenTip for that attribute
  4. Sanitize PenTip values in any third-party ISF producer

Example fix

// before
var attrs = DecodeAttributes(stream); // throws on unknown PenTip
// after
try { var attrs = DecodeAttributes(stream); }
catch (ArgumentException)
{
    attrs = new DrawingAttributes(); // defaults; log the invalid stream
}
Defensive patterns

Strategy: try-catch

Try / catch

try { attrs = DecodeDrawingAttributes(stream, guidList, maxSize); }
catch (ArgumentException ex) when (ex.Message.Contains("PenTip")) { attrs = new DrawingAttributes(); /* default fallback */ }

Prevention

When it happens

Trigger: Decoding ISF whose PenTip field contains an out-of-range uint — data written by a newer WPF with enum values this version doesn't know, a corrupt stream, or hand-crafted bytes.

Common situations: Forward-compatibility problems (newer PenTip values like the custom tip read by older runtimes); corrupt files; third-party ISF generators writing arbitrary ints.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/bf2e23eefe6a486a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/DrawingAttributeSerializer.cs:154

                maximumStreamSize -= cb;

                // Get the guid based on the tag
                Guid guid = guidList.FindGuid (tag);
                if (guid == Guid.Empty)
                {
                    throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Drawing Attribute tag embedded in ISF stream does not match guid table"));
                }

                uint dw = 0;

                if (KnownIds.PenTip == guid)
                {
                    cb = SerializationHelper.Decode (stream, out dw);
                    penTip = (PenTip)dw;
                    if (!PenTipHelper.IsDefined(penTip))
                    {
                        throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Invalid PenTip value found in ISF stream"));
                    }
                    maximumStreamSize -= cb;
                }
                else if (KnownIds.PenStyle == guid)
                {
                    cb = SerializationHelper.Decode(stream, out dw);
                    penStyle = (PenStyle)dw;
                    maximumStreamSize -= cb;
                }
                else if (KnownIds.DrawingFlags == guid)
                {
                    // Encode the drawing flags with considerations for v2 model
                    cb = SerializationHelper.Decode (stream, out dw);
                    DrawingFlags flags = (DrawingFlags)dw;
                    da.DrawingFlags = flags;
                    maximumStreamSize -= cb;
                }
                else if (KnownIds.RasterOperation == guid)

View on GitHub (pinned to 81131a70a4)