{"record":{"id":"56fdafee4ffe2bec","repo":"dotnet/wpf","slug":"sr-parserwriternoseekend","errorCode":null,"errorMessage":"SR.ParserWriterNoSeekEnd","messagePattern":"SR\\.ParserWriterNoSeekEnd","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlStream.cs","lineNumber":153,"sourceCode":"        /// Adjust the Writer's Seek Pointer.\n        /// Writer is not allowed to Seek before where the ReaderLength or\n        /// Seek past the writeLength.\n        /// </summary>\n        /// <param name=\"offset\">seek offset</param>\n        /// <param name=\"loc\">specifies how to interpret the seeek offset</param>\n        /// <returns></returns>\n        internal long WriterSeek(long offset, SeekOrigin loc)\n        {\n            switch(loc)\n            {\n                case SeekOrigin.Begin:\n                    WritePosition = (int) offset;\n                    break;\n                case SeekOrigin.Current:\n                    WritePosition = (int) (WritePosition + offset);\n                    break;\n                case SeekOrigin.End:\n                    throw new NotSupportedException(SR.ParserWriterNoSeekEnd);\n                default:\n                    throw new ArgumentException(SR.ParserWriterUnknownOrigin);\n            }\n\n            if( (!( WritePosition <= WriteLength ))\n                ||\n                (!( WritePosition >= ReadLength  )) )\n            {\n                throw new ArgumentOutOfRangeException( nameof(offset));\n            }\n\n            return WritePosition;\n        }\n\n\n        /// <summary>\n        /// Called by the Writer to indicate its okay for the reader to see\n        /// the file up to and including the position. Once the Writer calls","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlStream.cs#L135-L171","documentation":"XamlStream's internal writer stream's Seek method does not support seeking from SeekOrigin.End, and throws NotSupportedException(SR.ParserWriterNoSeekEnd). The stream is a buffered pipe between the BAML reader and writer, so its write position can only be set absolutely or relative to Current.","triggerScenarios":"Calling Seek(offset, SeekOrigin.End) on the write side of a XamlStream (e.g. setting stream.Position or Length-related operations that seek from the end).","commonSituations":"Code that generically seeks relative to End (a common Stream idiom for finding stream length or appending) applied to the internal XAML parser stream.","solutions":["Use SeekOrigin.Begin with an absolute offset instead of SeekOrigin.End.","Track the desired position from the stream length manually and seek from Begin.","Rewrite code to avoid End-relative seeks on this stream type."],"exampleFix":"// before\nstream.Seek(0, SeekOrigin.End);\n// after\nstream.Seek(stream.Length, SeekOrigin.Begin);","handlingStrategy":"validation","validationCode":"if (origin == SeekOrigin.End) throw new InvalidOperationException(\"End-relative seek not supported on XamlStream writer\");","typeGuard":null,"tryCatchPattern":"try { stream.Seek(offset, origin); }\ncatch (NotSupportedException) { stream.Seek(stream.Length + offset, SeekOrigin.Begin); }","preventionTips":["Avoid SeekOrigin.End on WPF internal parser streams.","Convert End-relative seeks to absolute Begin-relative positions.","Read the stream's documented capabilities before seeking."],"tags":["wpf","xaml","io","stream"],"backgroundTag":"operation-not-supported","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"}