{"record":{"id":"a631611f7294dc5a","repo":"dotnet/wpf","slug":"sr-invalid-isfdata-length","errorCode":null,"errorMessage":"SR.Invalid_isfData_Length","messagePattern":"SR\\.Invalid_isfData_Length","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection.cs","lineNumber":66,"sourceCode":"                }\n                items.Add(stroke);\n            }\n        }\n\n        /// <summary>Creates a collection from ISF data in the specified stream</summary>\n        /// <param name=\"stream\">Stream of ISF data</param>\n        public StrokeCollection(Stream stream)\n        {\n            ArgumentNullException.ThrowIfNull(stream);\n            if ( !stream.CanRead )\n            {\n                throw new ArgumentException(SR.Image_StreamRead, nameof(stream));\n            }\n\n            Stream seekableStream = GetSeekableStream(stream);\n            if (seekableStream == null)\n            {\n                throw new ArgumentException(SR.Invalid_isfData_Length, nameof(stream));\n            }\n\n            //this will init our stroke collection\n            StrokeCollectionSerializer serializer = new StrokeCollectionSerializer(this);\n            serializer.DecodeISF(seekableStream);\n        }\n\n\n        /// <summary>Save the collection of strokes, including any custom attributes to a stream</summary>\n        /// <param name=\"stream\">The stream to save Ink Serialized Format to</param>\n        /// <param name=\"compress\">Flag if set to true the data will be compressed, which can\n        /// reduce the output buffer size in exchange for slower Save performance.</param>\n        public virtual void Save(Stream stream, bool compress)\n        {\n            ArgumentNullException.ThrowIfNull(stream);\n            if ( !stream.CanWrite )\n            {\n                throw new ArgumentException(SR.Image_StreamWrite, nameof(stream));","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection.cs#L48-L84","documentation":"After confirming readability, the StrokeCollection(Stream) constructor calls GetSeekableStream; ISF decoding requires a seekable stream, and when none can be obtained it throws ArgumentException(SR.Invalid_isfData_Length). The stream data must be seekable and correspond to valid ISF data of decodable length.","triggerScenarios":"Passing a non-seekable stream (e.g. NetworkStream, GZipStream wrapper, or a forward-only pipe) whose content cannot be buffered into a seekable stream; passing a stream with truncated/invalid ISF data.","commonSituations":"Loading ink directly from an HTTP response stream or socket stream; ISF files that were truncated by an interrupted write; deserializing non-ISF data saved by another tool.","solutions":["Copy the stream into a MemoryStream before constructing: new StrokeCollection(new MemoryStream(stream bytes))","Verify the source really is ISF data (written via StrokeCollection.Save)","Check the stream length/content for truncation before decoding"],"exampleFix":"// before\nvar sc = new StrokeCollection(networkStream);\n// after\nusing var ms = new MemoryStream();\nnetworkStream.CopyTo(ms);\nms.Position = 0;\nvar sc = new StrokeCollection(ms);","handlingStrategy":"try-catch","validationCode":"bool usable = stream is not null && stream.CanRead && (stream.CanSeek || true); // prefer: buffer into MemoryStream when !stream.CanSeek","typeGuard":"static bool IsSeekable(Stream? s) => s is not null && s.CanRead && s.CanSeek;","tryCatchPattern":"try { var sc = new StrokeCollection(stream); } catch (ArgumentException ex) when (ex.ParamName == \"stream\") { using var ms = new MemoryStream(); stream.CopyTo(ms); ms.Position = 0; var sc = new StrokeCollection(ms); }","preventionTips":["Buffer non-seekable streams (network/gzip) into MemoryStream before decoding","Verify data is genuine ISF produced by Save","Check stream length for truncation"],"tags":["wpf","ink","stream","isf"],"backgroundTag":"invalid-argument-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}