Azure.Storage.Blobs returns different list from WindowsAzure.Storage on creation

Itai Bar-Haim 1 Reputation point
2021-12-20T10:47:05.293+00:00

I have this test code which connects to Azure Blob Storage in two ways with the same credentials, once with the now deprecated WindowsAzure.Storage package and once the new Azure.Storage.Blobs package:

using Azure.Storage.Blobs;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using NUnit.Framework;
using System.Linq;

namespace EntityFrameworkTest
{
    public class AzureBlobStorageTests
    {

        [Test]
        public void TestStorage()
        {
            string storageAccount = "MyConnectionString";
            string containerName = "testazureblobobjectstore";

            var clientNew = new BlobServiceClient(storageAccount);
            var containerNew = clientNew.GetBlobContainerClient(containerName);
            containerNew.CreateIfNotExists();
            var blobsListNew = containerNew.GetBlobs();

            var accountOld = CloudStorageAccount.Parse(storageAccount);
            var clientOld = accountOld.CreateCloudBlobClient();
            var containerOld = clientOld.GetContainerReference(containerName);
            containerOld.CreateIfNotExistsAsync().GetAwaiter().GetResult();
            BlobContinuationToken config = new BlobContinuationToken();
            var blobsListOld = containerOld.ListBlobsSegmentedAsync(config).GetAwaiter().GetResult().Results;

            Assert.AreEqual(blobsListOld.Count(), blobsListNew.Count());
        }
    }
}

The lengths of the two lists differ:

In blobsListOld I have 2 items:

  1. The directory
  2. A BlockBlob with name __id__foo.

In blobsListNew I have 3 items, all are BlockBlobs with the following names:

  1. //||!@#$%^&*()_-=+[]'<>~;:`?
  2. /||!@#$%^&*()_-=+[]'<>~;:`?
  3. __id__foo.

Can anyone explain this to me please?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,199 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ravi Kanth Koppala 3,391 Reputation points Microsoft Employee Moderator
    2021-12-21T04:22:45.913+00:00

    @Itai Bar-Haim ,
    I reproduced the scenario using a console application and I don't see much difference in the outcome. Can you please recreate your scenario in the new container to check if you are receiving the same outcome.

    For example, if I have only a file in the container, here is the outcome I got.
    New Namespace
    __id__foo.txt
    Old Namespace
    __id__foo.txt

    If I have two files in the container, 1st at the root and another one in a directory, here is the outcome I got.
    New Namespace
    __id__foo.txt
    folder/__id__foo1.txt
    Old Namespace
    __id__foo.txt
    folder/

    Here is the code I used to test the scenario

    string storageAccount = "connection string";  
                string containerName = "testazureblobobjectstore";  
                var clientNew = new BlobServiceClient(storageAccount);  
                var containerNew = clientNew.GetBlobContainerClient(containerName);  
                containerNew.CreateIfNotExists();  
                Console.WriteLine("New Namespace");  
                foreach (var blobItem in containerNew.GetBlobs())  
                {  
                    Console.WriteLine("\t" + blobItem.Name);  
                }  
                var accountOld = CloudStorageAccount.Parse(storageAccount);  
                var clientOld = accountOld.CreateCloudBlobClient();  
                var containerOld = clientOld.GetContainerReference(containerName);  
                containerOld.CreateIfNotExistsAsync().GetAwaiter().GetResult();  
                BlobContinuationToken config = new BlobContinuationToken();  
                var blobsListOld = containerOld.ListBlobsSegmentedAsync(config).GetAwaiter().GetResult().Results;  
                Console.WriteLine("Old Namespace");  
                foreach (var blobItem in blobsListOld)  
                {  
                    if(blobItem is CloudBlobDirectory)  
                    {  
                        Console.WriteLine("\t" + ((CloudBlobDirectory)blobItem).Prefix);  
                    }  
                    if(blobItem is CloudBlockBlob)  
                    {  
                        Console.WriteLine("\t" + ((CloudBlockBlob)blobItem).Name);  
                    }  
                }  
                System.Console.ReadLine();  
    

  2. Itai Bar-Haim 21 Reputation points
    2021-12-22T09:00:20.803+00:00

    So apparently I had to use containerNew.GetBlobsByHierarchy(delimiter: "/"); to get only the blobs in the root folder.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.