{"record":{"id":"9d185b45fdb25646","repo":"dotnet/wpf","slug":"sr-image-streamread","errorCode":null,"errorMessage":"SR.Image_StreamRead","messagePattern":"SR\\.Image_StreamRead","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection.cs","lineNumber":60,"sourceCode":"            {\n                if ( items.Contains(stroke) )\n                {\n                    //clear and throw\n                    items.Clear();\n                    throw new ArgumentException(SR.StrokeIsDuplicated, nameof(strokes));\n                }\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>","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection.cs#L42-L78","documentation":"The StrokeCollection(Stream stream) constructor decodes Ink Serialized Format (ISF) from the stream. After a null check it verifies stream.CanRead; if the stream is not readable it throws ArgumentException(SR.Image_StreamRead). The stream must support reading before ISF decoding can proceed.","triggerScenarios":"Passing a write-only stream (e.g. opened with FileAccess.Write) or a closed stream to the StrokeCollection(Stream) constructor.","commonSituations":"Loading ink from a FileStream opened with wrong FileMode/FileAccess; passing a response/request body stream positioned for writing; using a disposed or closed stream.","solutions":["Open the source with read access (FileMode.Open, FileAccess.Read) before constructing","Check stream.CanRead in the caller and open a new readable stream if false","If the source is write-only, copy its content to a MemoryStream first and pass that"],"exampleFix":"// before\nusing var fs = new FileStream(path, FileMode.Append, FileAccess.Write);\nvar sc = new StrokeCollection(fs);\n// after\nusing var fs = new FileStream(path, FileMode.Open, FileAccess.Read);\nvar sc = new StrokeCollection(fs);","handlingStrategy":"validation","validationCode":"bool readable = stream is not null && stream.CanRead;","typeGuard":"static bool IsReadableStream(Stream? s) => s is not null && s.CanRead;","tryCatchPattern":"try { var sc = new StrokeCollection(stream); } catch (ArgumentException ex) when (ex.ParamName == \"stream\") { /* open a readable stream and retry */ }","preventionTips":["Open streams with FileAccess.Read when loading ink","Check CanRead before ISF decode calls","Never reuse write-oriented streams for reading"],"tags":["wpf","ink","stream","isf"],"backgroundTag":"file-read-failed","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"}