abpframework/abp · warning · NotSupportedException

The position of the stream is not available!

Error message

The position of the stream is not available!

What it means

LeaveOpenStreamWrapper.Position getter re-throws an IOException from the inner stream as a NotSupportedException ('The position of the stream is not available!'). It mirrors the Length translation so the AWS SDK (which only handles NotSupportedException on Position probes) degrades gracefully to 'unknown position' rather than failing the upload. The original IOException is kept as InnerException; the setter still delegates to the inner stream.

Source

Thrown at framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/LeaveOpenStreamWrapper.cs:53

            }
            catch (IOException ex)
            {
                throw new NotSupportedException("The length of the stream is not available!", ex);
            }
        }
    }

    public override long Position
    {
        get
        {
            try
            {
                return _inner.Position;
            }
            catch (IOException ex)
            {
                throw new NotSupportedException("The position of the stream is not available!", ex);
            }
        }
        set => _inner.Position = value;
    }

    public override void Flush()
    {
    }

    public override int Read(byte[] buffer, int offset, int count) => _inner.Read(buffer, offset, count);

    public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
    {
#if NETSTANDARD2_0
        return _inner.ReadAsync(buffer, offset, count, cancellationToken);
#else
        // The SDK reads over this (old) overload; dispatch it over the modern one,
        // so a source that only implements ReadAsync(Memory<byte>) keeps working

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Buffer the source into a seekable MemoryStream so Position is always readable.
  2. Let the SDK continue with unknown position (the translation exists for that case).
  3. Provide a seekable stream when the upload path requires resuming/seeking.

Example fix

// before
await container.SaveAsync(name, forwardOnlyStream);

// after
using var buffer = new MemoryStream();
await forwardOnlyStream.CopyToAsync(buffer);
buffer.Position = 0;
await container.SaveAsync(name, buffer);
Defensive patterns

Strategy: fallback

Validate before calling

Stream uploadStream = sourceStream;
if (!sourceStream.CanSeek)
{
    using var buffer = new MemoryStream();
    await sourceStream.CopyToAsync(buffer);
    buffer.Position = 0;
    uploadStream = buffer;
}
await container.SaveAsync(name, uploadStream);

Type guard

bool positionAvailable = sourceStream.CanSeek;

Try / catch

catch (NotSupportedException ex) when (ex.Message.Contains("position of the stream"))
{
    using var buffer = new MemoryStream();
    await sourceStream.CopyToAsync(buffer); buffer.Position = 0;
    await container.SaveAsync(name, buffer);
}

Prevention

When it happens

Trigger: During a wrapped AWS upload the SDK reads the Position property of the LeaveOpenStreamWrapper and the inner stream throws IOException (non-seekable / network-backed stream). The wrapper translates it so the upload can continue without a known position.

Common situations: Uploading from a forward-only stream that cannot report Position, or a stream whose Position accessor throws. Normally absorbed by the SDK; surfaces only if code outside the SDK probes Position.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/f184ffdcbb50c25f. Report an issue: GitHub.