dotnet/wpf · error · ArgumentException

SR.IsfOperationFailed

Error message

SR.IsfOperationFailed

What it means

DecodeISF is the top-level ISF deserializer; in DEBUG builds it catches ArgumentException from the decoding pipeline and rethrows ArgumentException(SR.IsfOperationFailed) with the original exception as InnerException. The message is intentionally generic - the real cause is in the inner exception (e.g. a bad guid tag, bad huffman data, or other malformed ISF content).

Solutions

  1. Inspect ex.InnerException (DEBUG builds) to find the root cause.
  2. Validate the stream is a complete, well-formed ISF payload (header check) before decoding.
  3. Regenerate/re-export the ISF data from the originating application.
  4. Catch ArgumentException around StrokeCollection construction and show a generic 'invalid ink data' message to users.

Example fix

// before
StrokeCollection sc = new StrokeCollection(isfStream); // throws IsfOperationFailed
// after
try { StrokeCollection sc = new StrokeCollection(isfStream); }
catch (ArgumentException ex)
{
    Log(ex.InnerException ?? ex); // root cause in DEBUG builds
    sc = new StrokeCollection(); // fallback empty
}
Defensive patterns

Strategy: try-catch

Validate before calling

bool LooksLikeIsf(Stream s) { var hdr = new byte[16]; int n = s.Read(hdr,0,16); s.Position=0; return n==16 && hdr[0]==KnownIdCache.IsfHeaderFirstByte; }

Try / catch

try { strokes = new StrokeCollection(isfStream); }
catch (ArgumentException ex) { Log(ex.InnerException ?? ex); ShowInvalidInkMessage(); }

Prevention

When it happens

Trigger: Calling StrokeCollection(ISF stream) / DecodeAsISF on a stream that causes any ArgumentException inside decoding - e.g. a tag outside the known guid range, invalid transforms, or bad compressed data.

Common situations: Loading .isf files saved by other apps, deserializing clipboard ink (CF_INK_SERIALIZED_FORMAT), consuming user-uploaded ink payloads.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/InkSerializedFormat/InkSerializer.cs:133

                    else
                    {
                        DecodeRawISF(ms);
                    }
                }
                else if (isGif)
                {
                    DecodeRawISF(SystemDrawingHelper.GetCommentFromGifStream(inkData));
                }
                else
                {
                    DecodeRawISF(inkData);
                }
            }
#if DEBUG
            catch (ArgumentException ex)
            {
                //only include an inner exception in debug builds
                throw new ArgumentException(SR.IsfOperationFailed, ex);
            }
            catch (InvalidOperationException ex)
            {
                //only include an inner exception in debug builds
                throw new ArgumentException(SR.IsfOperationFailed, ex);
            }
            catch (IndexOutOfRangeException ex)
            {
                //only include an inner exception in debug builds
                throw new ArgumentException(SR.IsfOperationFailed, ex);
            }
            catch (NullReferenceException ex)
            {
                //only include an inner exception in debug builds
                throw new ArgumentException(SR.IsfOperationFailed, ex);
            }
            catch (EndOfStreamException ex)
            {

View on GitHub (pinned to 81131a70a4)