Search code examples
c#.netazureazure-storageazure-sdk

InvalidRange error when downloading empty file from Azure File Shares with .NET SDK


I am trying to download an empty file from an Azure File Share with the tools provided in Azure.Storage.Files.Shares. Downloading a file which contains more than 0 bytes works fine. However, in my integration tests, I am creating/downloading empty files. For my tests it's not a big deal to just use populated files, but it's not unreasonable that an empty file could be accidentally uploaded and chosen for download in our application. So here's the problem:

I am getting an InvalidRange error:

Status: 416 (The range specified is invalid for the current size of the resource.)
    ErrorCode: InvalidRange
    
    Content:
    <?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidRange</Code><Message>The range specified is invalid for the current size of the resource.
    RequestId:9f04885b-401a-005e-80fa-77d94a000000
    Time:2021-07-13T15:16:59.9547272Z</Message></Error>
    
    Headers:
    Content-Range: bytes */0
    x-ms-request-id: 9f04885b-401a-005e-80fa-77d94a000000
    x-ms-client-request-id: a6ee7be7-7ae9-4587-b28c-d6a15cd499e8
    x-ms-version: 2020-08-04
    x-ms-error-code: InvalidRange
    Content-Length: 249
    Content-Type: application/xml
    Date: Tue, 13 Jul 2021 15:16:59 GMT
    Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0

My download code is the code provided in this example code:

ShareFileDownloadInfo download = file.Download();
using (FileStream stream = File.OpenWrite(localFilePath))
{
    download.Content.CopyTo(stream);
}

Again, it works fine for files that aren't empty. The documentation for the underlying storage REST API says that 'Range' is an optional parameter that, when left empty, will download all of the file content by default. I know it's possible to do because the files are downloadable manually through the Azure Portal.

Is this a bug or is this download code incomplete?


Solution

  • Confirmed as a bug. Track here https://github.com/Azure/azure-sdk-for-net/issues/22616