{"record":{"id":"6fbf752363e40ade","repo":"dotnet/wpf","slug":"sr-image-streamwrite","errorCode":null,"errorMessage":"SR.Image_StreamWrite","messagePattern":"SR\\.Image_StreamWrite","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection.cs","lineNumber":84,"sourceCode":"                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));\n            }\n            SaveIsf(stream, compress);\n        }\n\n        /// <summary>Save the collection of strokes uncompressed, including any custom attributes to a stream</summary>\n        /// <param name=\"stream\">The stream to save Ink Serialized Format to</param>\n        public void Save(Stream stream)\n        {\n            Save(stream, true);\n        }\n\n        /// <summary>\n        /// Internal method for getting just the byte[] out\n        /// </summary>\n        internal void SaveIsf(Stream stream, bool compress)\n        {\n            StrokeCollectionSerializer serializer = new StrokeCollectionSerializer(this)\n            {","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/StrokeCollection.cs#L66-L102","documentation":"StrokeCollection.Save(Stream, bool) writes the collection as ISF to the given stream. It requires stream.CanWrite; a non-writable stream causes ArgumentException(SR.Image_StreamWrite). The stream must be writable for ISF serialization to proceed.","triggerScenarios":"Calling Save on a stream opened with FileAccess.Read, a read-only FileStream, or a closed/disposed stream.","commonSituations":"Saving ink to a file opened read-only by mistake; writing to a stream retrieved from a read-only resource; passing an input stream variable where an output stream was intended.","solutions":["Open the destination with write access (FileMode.Create, FileAccess.Write) before calling Save","Check stream.CanWrite in the caller and re-open a writable stream if false","Wrap the destination in a MemoryStream if the ultimate target is read-only, then copy it out"],"exampleFix":"// before\nusing var fs = new FileStream(path, FileMode.Open, FileAccess.Read);\nstrokes.Save(fs, true);\n// after\nusing var fs = new FileStream(path, FileMode.Create, FileAccess.Write);\nstrokes.Save(fs, true);","handlingStrategy":"validation","validationCode":"bool writable = stream is not null && stream.CanWrite;","typeGuard":"static bool IsWritableStream(Stream? s) => s is not null && s.CanWrite;","tryCatchPattern":"try { strokes.Save(stream, compress: true); } catch (ArgumentException ex) when (ex.ParamName == \"stream\") { /* open a writable stream and retry */ }","preventionTips":["Open destination streams with FileAccess.Write","Check CanWrite before calling Save","Dispose/reopen closed streams rather than reusing them"],"tags":["wpf","ink","stream","isf"],"backgroundTag":"file-write-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"}