question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] A open stream with BlobOpenReadOptions(true) says that stream.canSeek true but says cannot seek on end

See original GitHub issue

Describe the bug A open stream with BlobOpenReadOptions(true) says that stream.canSeek true but says cannot seek on end. In my case, the stream is handed over to external libraries and on this point there is no possibility to check which seek is used.

Expected behavior As the error message says that ‘Cannot Seek with SeekOrigin.End on a growing blob or file. Call Stream.Seek(Stream.Length, SeekOrigin.Begin) to get to the end of known data.’ The value of stream.canSeek should be false or Seek(0, SeekOrigin.End) should work like Seek(Stream.Lenght, SeekOrigin.Begin)

Actual behavior (include Exception or Stack Trace) System.ArgumentException: ‘Cannot Seek with SeekOrigin.End on a growing blob or file. Call Stream.Seek(Stream.Length, SeekOrigin.Begin) to get to the end of known data. Arg_ParamName_Name’

To Reproduce

        [SkippableFact]
        public async void TestDecompressErrorForZip()
        {
            string connectionString = Constants.ConnectionStringTestBlobStorage;
            string fileName = $"anyfile{Guid.NewGuid()}.zip";
            BlobContainerClient blobContainerClient= new BlobContainerClient(connectionString, Constants.TestContainerName.Value);
            
            BlobClient blob = blobContainerClient.GetBlobClient(fileName);
            await blob.UploadAsync("anyfile.zip");


            using (var fileStreamErr = await blob.OpenReadAsync(new BlobOpenReadOptions(false)))
            {
                if (fileStreamErr.CanSeek)
                {
                    fileStreamErr.ReadByte();
                    fileStreamErr.Seek(0, SeekOrigin.Begin);
                    fileStreamErr.Seek(0, SeekOrigin.End);
                }
            }

            using (var fileStreamErr = await blob.OpenReadAsync(new BlobOpenReadOptions(true)))
            {
                if (fileStreamErr.CanSeek)
                {
                    fileStreamErr.ReadByte();
                    fileStreamErr.Seek(0, SeekOrigin.Begin);
                    // This should not fail, because CanSeek is true
                    fileStreamErr.Seek(0, SeekOrigin.End);
                }
            }
        }

Environment:

  • Azure.Storage.Blobs 12.9.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
seanmcc-msftcommented, Aug 12, 2021

Unfortunately, changing this behavior may be considered a breaking change, which we are not allowed to make. Other users may have taken a dependency on this behavior.

0reactions
MartinDembergercommented, Aug 13, 2021

You anyone is expect a exception to be thrown when he calls a method which says “you are not allowed to do this”. I understand your point of backward compatibility but think it’s only academical in this case because you remove a “fobiden” sign. Every one who expect the exception won’t call this method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# Stream.CanSeek property, This Stream Doesn't Support ...
NotSupportedException: 'This stream does not support seek operations.' when I try accessing body.Length and I noticed there is CanSeek property ...
Read more >
FileStream.CanSeek Property (System.IO)
Gets a value that indicates whether the current stream supports seeking. ... true if the stream supports seeking; false if the stream is...
Read more >
[BUG] BlockBlobClient requires seekable streams #7871
Describe the bug BlockBlobClient::UploadInternal() creates lambdas that call Seek() on the stream passed in. This stream can be one directly ...
Read more >
How to enable seeking in Azure Blob stream
CanSeek =true and calls stream.Seek with incoming contentrangeheader's range.from value. So wrap the source with return new SeekableBlobReadStream(blobclient) ...
Read more >
C# Program to Demonstrate the Use of CanSeek Property
This property is used to find a value that determines whether the current stream supports seeking or not. If the returned value is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found