dotnet/wpf · error · NotSupportedException

SR.SeekNotSupported

Error message

SR.SeekNotSupported

What it means

CFStream.Seek throws NotSupportedException with SR.SeekNotSupported when CanSeek is false, i.e. the underlying compound-file stream cannot be seeked in its current state (e.g. write/append-only). Any explicit Seek call is rejected before contacting IStream.

Solutions

  1. Check CanSeek before calling Seek on the CFStream
  2. Do not attempt seek operations on a stream opened over an IStream without seek capability
  3. Buffer or copy the content into a seekable MemoryStream if seeking is required
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CFStream.cs:146 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/CompoundFile/CFStream.cs:146

    public override void Flush()
    {
        CheckDisposedStatus();
        _safeIStream.Commit(0);
    }

    /// <summary>
    /// See .NET Framework SDK under System.IO.Stream
    /// </summary>
    /// <param name="offset">Offset byte count</param>
    /// <param name="origin">Offset origin</param>
    /// <returns></returns>
    public override long Seek( long offset, SeekOrigin origin )
    {
        CheckDisposedStatus();

        if (!CanSeek)
        {
            throw new NotSupportedException(SR.SeekNotSupported);
        }
        
        // 
        long seekPos = 0;
        int translatedSeekOrigin = 0;

        switch(origin)
        {
            case SeekOrigin.Begin:
                translatedSeekOrigin = SafeNativeCompoundFileConstants.STREAM_SEEK_SET;
                if( 0 > offset )
                {
                    throw new ArgumentOutOfRangeException(nameof(offset),
                        SR.SeekNegative);
                }
                break;
            case SeekOrigin.Current:
                translatedSeekOrigin = SafeNativeCompoundFileConstants.STREAM_SEEK_CUR;

View on GitHub (pinned to 81131a70a4)