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] ObjectReplicationSourceProperties is null

See original GitHub issue

Library name and version

Azure.Storage.Blobs v12.10.0

Describe the bug

We are testing the Object Replication feature for blobs. Based on this link we should be able to check the replication status of the blobs through the ObjectReplicationSourceProperties. However, the property is coming as null for all blobs. As a result, blob.ObjectReplicationSourceProperties[0].Rules[0].ReplicationStatus does not work and throws null reference exception. We are testing this on an account where the replication has already taken place and the replicated blobs can be seen in the destination account. However, the ObjectReplicationSourceProperties is coming as null for blobs in both source and destination accounts. In the Azure portal, the replication properties are visible.

Expected behavior

ObjectReplicationSourceProperties[0].Rules[0].ReplicationStatus should return complete or failure for blobs in storage accounts where replication policy has been applied.

Actual behavior

ObjectReplicationSourceProperties is coming as null.

Reproduction Steps

  1. Followed the steps in this page for the portal to create the replication policies: https://docs.microsoft.com/en-us/azure/storage/blobs/object-replication-configure?tabs=portal

  2. Used the code below to list and iterate through the blobs. Replace the variables in <> for the account, container, access key

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Azure;
using Azure.Storage;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;

namespace TestBlobReplication
{
    class Program
    {
        //Azure storage account information
        private static readonly string storageAccountName = <**STORAGE ACCOUNT NAME**>;
        private static readonly string storageContainerName = <**CONTAINER NAME**>;
        private static readonly string AzureStoragePrimaryKey = <**PRIMARY ACCESS KEY**>;
        private static readonly string AzureStorageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={AzureStoragePrimaryKey};EndpointSuffix=core.windows.net";

        private static BlobContainerClient blobContainerClient;

        public async Task<BlobContainerClient> GetBlobContainerReferenceAsync(string containerName)
        {
            var blobContainerClient = new BlobContainerClient(AzureStorageConnectionString, containerName);
            bool exists = await blobContainerClient.ExistsAsync();

            if (exists)
            {
                Console.WriteLine($"{DateTime.Now} \n2. Found Container \n{containerName}\n");
            }
            else
            {
                await blobContainerClient.CreateAsync();
                Console.WriteLine($"{DateTime.Now} Blob container: {containerName} inside storage account: {blobContainerClient.AccountName} does not exist, container created");
                //throw new InvalidOperationException("Storage Account/Container not found");
            }

            return blobContainerClient;
        }

        public async Task<IList<BlobItem>> ListBlobMetadataAsync(
            string prefix,
            string continuationToken,
            int maxResultCount = 5000)
        {
            // TODO: make this.container auto initialize   
            IAsyncEnumerable<Page<BlobItem>> blobPages = blobContainerClient.GetBlobsAsync(
                BlobTraits.Metadata,
                BlobStates.None,
                prefix)
                .AsPages(continuationToken, maxResultCount);

            IAsyncEnumerator<Page<BlobItem>> enumerator = blobPages.GetAsyncEnumerator();
            IList<BlobItem> resultSegment = new List<BlobItem>();
            string newContinuationToken = null;

            try
            {
                while (await enumerator.MoveNextAsync())
                {
                    Page<BlobItem> blobPage = enumerator.Current;
                    foreach (BlobItem blobItem in blobPage.Values)
                    {
                        resultSegment.Add(blobItem);
                    }
                    newContinuationToken = blobPage.ContinuationToken;
                }
            }
            finally
            {
                await enumerator.DisposeAsync();
            }

            return resultSegment;
        }

        static async Task Main(string[] args)
        {
            Console.WriteLine($"{DateTime.Now} Beginning operations...");
            Program p = new Program();

            blobContainerClient = await p.GetBlobContainerReferenceAsync(storageContainerName);
            //BlobClient blobClient = blobContainerClient.GetBlobClient(blobId);
            IList<BlobItem> blobs = await p.ListBlobMetadataAsync(null, null);

            foreach (var blob in blobs)
            {
                var metadata = blob.Metadata;
                var createdTime = blob.Properties.CreatedOn;
                var replicated = blob.ObjectReplicationSourceProperties[0].Rules[0].ReplicationStatus;
            }
        }
    }
}

Environment

.NET CORE 3.1 Visual Studio 2019

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jsquirecommented, Mar 1, 2022

Tagged the wrong person @jsquire Jesse 😃

Apologies; that’s my mistake.

1reaction
amishra-devcommented, Feb 28, 2022

Tagged the wrong person @jsquire Jesse 😃

@asgoe, lets sort it out over email and we can put the summary here. I do apologize for the delay

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting null value for Azure blob last modified property
It essentially creates a new instance of CloudBlockBlob object and it's properties are initialized to the default value.
Read more >
Object replication for block blobs - Azure Storage
Object replication asynchronously copies block blobs between a source ... property for a storage account is null or true, then authorized ...
Read more >
Azure SDK for Java (July 2020)
Fixed null pointer exception on request manager in RntbdClientChannelPool. Azure Identity (Changelog. 1.1.0-beta.6 (2020-07-10). Added .
Read more >
Azure Blob Storage module for Go
NewListContainersPager operation returns a pager of the containers under the specified account. Use an empty Marker to start enumeration from ...
Read more >
BlobContainerClient (Azure SDK for Java Reference ...
Initializes a new BlobClient object by concatenating blobName to the end of ContainerAsyncClient's URL. The new BlobClient uses the same request policy ...
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