[BUG] ObjectReplicationSourceProperties is null
See original GitHub issueLibrary 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
-
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
-
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:
- Created 2 years ago
- Comments:15 (8 by maintainers)
Top GitHub Comments
Apologies; that’s my mistake.
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