dotnet/wpf · error · NotSupportedException

SR.ParserWriterNoSeekEnd

Error message

SR.ParserWriterNoSeekEnd

What it means

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.

Solutions

  1. Use SeekOrigin.Begin with an absolute offset instead of SeekOrigin.End.
  2. Track the desired position from the stream length manually and seek from Begin.
  3. Rewrite code to avoid End-relative seeks on this stream type.

Example fix

// before
stream.Seek(0, SeekOrigin.End);
// after
stream.Seek(stream.Length, SeekOrigin.Begin);
Defensive patterns

Strategy: validation

Validate before calling

if (origin == SeekOrigin.End) throw new InvalidOperationException("End-relative seek not supported on XamlStream writer");

Try / catch

try { stream.Seek(offset, origin); }
catch (NotSupportedException) { stream.Seek(stream.Length + offset, SeekOrigin.Begin); }

Prevention

When it happens

Trigger: 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).

Common situations: Code that generically seeks relative to End (a common Stream idiom for finding stream length or appending) applied to the internal XAML parser stream.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlStream.cs:153

        /// Adjust the Writer's Seek Pointer.
        /// Writer is not allowed to Seek before where the ReaderLength or
        /// Seek past the writeLength.
        /// </summary>
        /// <param name="offset">seek offset</param>
        /// <param name="loc">specifies how to interpret the seeek offset</param>
        /// <returns></returns>
        internal long WriterSeek(long offset, SeekOrigin loc)
        {
            switch(loc)
            {
                case SeekOrigin.Begin:
                    WritePosition = (int) offset;
                    break;
                case SeekOrigin.Current:
                    WritePosition = (int) (WritePosition + offset);
                    break;
                case SeekOrigin.End:
                    throw new NotSupportedException(SR.ParserWriterNoSeekEnd);
                default:
                    throw new ArgumentException(SR.ParserWriterUnknownOrigin);
            }

            if( (!( WritePosition <= WriteLength ))
                ||
                (!( WritePosition >= ReadLength  )) )
            {
                throw new ArgumentOutOfRangeException( nameof(offset));
            }

            return WritePosition;
        }


        /// <summary>
        /// Called by the Writer to indicate its okay for the reader to see
        /// the file up to and including the position. Once the Writer calls

View on GitHub (pinned to 81131a70a4)