dotnet/wpf · error · ArgumentException

Tag is outside of the known guid tag range

Error message

Tag is outside of the known guid tag range

What it means

FindKnownGuid converts a known ISF tag to a .NET Guid but only for tags in the 'known guid' range (>= KnownIdCache.KnownGuidBaseIndex). When a tag below that base index reaches it, the tag is not a valid known guid tag, so the ISF serializer throws ArgumentException with this ISF debug message.

Solutions

  1. Verify the ISF stream is complete and uncorrupted before decoding (check stream length and header).
  2. Confirm the data was produced by a compatible ISF writer version; regenerate the ISF payload.
  3. Validate the KnownTagCache.KnownTagIndex value is >= KnownIdCache.KnownGuidBaseIndex before calling FindGuid/guid.
  4. Wrap DecodeAsISF/StrokeCollection construction in a try-catch for ArgumentException and treat the stream as invalid.

Example fix

// before
Guid g = KnownTags.FindGuid(tag); // throws for bad tag
// after
if ((int)tag >= KnownIdCache.KnownGuidBaseIndex)
{
    Guid g = KnownTags.FindGuid(tag);
}
else
{
    // skip unknown tag or fail gracefully
}
Defensive patterns

Strategy: validation

Validate before calling

bool IsValidKnownTag(KnownTagCache.KnownTagIndex t) => (int)t >= (int)KnownIdCache.KnownGuidBaseIndex;

Type guard

static bool IsValidKnownTag(KnownTagCache.KnownTagIndex tag) => tag >= KnownIdCache.KnownGuidBaseIndex;

Try / catch

try { Guid g = KnownTags.FindGuid(tag); }
catch (ArgumentException ex) { Log(ex); return Guid.Empty; }

Prevention

When it happens

Trigger: Decoding an ISF stream whose tag byte/uint encodes a tag that falls below KnownGuidBaseIndex - i.e. a corrupt, truncated, or hand-crafted ISF payload, or a caller passing an invalid KnownTagCache.KnownTagIndex into guid/FindGuid.

Common situations: Parsing ISF files produced by third-party tools, clipboard ink data that was mangled in transit, or unit tests feeding arbitrary tag values into the ISF decoder.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/GuidTagList.cs:113

                tag = FindCustomTag(guid);
                if (KnownTagCache.KnownTagIndex.Unknown == tag)
                    tag = FindKnownTag(guid);
            }

            return tag;
        }


        /// <summary>
        /// Finds a known guid based on a Tag
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        private static Guid FindKnownGuid(KnownTagCache.KnownTagIndex tag)
        {
            if (tag < KnownIdCache.KnownGuidBaseIndex)
            {
                throw new ArgumentException(StrokeCollectionSerializer.ISFDebugMessage("Tag is outside of the known guid tag range"));
            }

            // Get the index in the OriginalISFIdTable array first
            uint nIndex = (uint)(tag - KnownIdCache.KnownGuidBaseIndex);

            // If invalid, return Guid.Empty
            if (KnownIdCache.OriginalISFIdTable.Length <= nIndex)
                return Guid.Empty;

            // Otherwise, return the guid
            return KnownIdCache.OriginalISFIdTable[nIndex];
        }


        /// <summary>
        /// Finds a Custom Guid based on a Tag
        /// </summary>
        /// <param name="tag"></param>

View on GitHub (pinned to 81131a70a4)