Assistance Required with Tags Property Error in Azure Blob Storage Application

vievillage 60 Reputation points
2023-11-05T16:24:38.0933333+00:00

Hello,

I am currently developing an application using Azure Blob Storage and have encountered an error related to the Tags property of the BlobInfo class. Despite the Tags property being defined in the class, I am receiving an error indicating that the property does not exist.

Error Message:
'BlobInfo' does not contain a definition for 'Tags' and no accessible extension method 'Tags' accepting a first argument of type 'BlobInfo' could be found (are you missing a using directive or an assembly reference?)

public class BlobInfo
{
    public string ImageUri { get; set; }
    public string ThumbnailUri { get; set; }
    public string Caption { get; set; }
    public List<string> Tags { get; set; } = new List<string>();
}

// In BlobInfoService.cs
public async Task<List<BlobInfo>> ListBlobsWithMetadataAsync(string containerName)
{
    List<BlobInfo> blobs = new List<BlobInfo>();
    BlobContainerClient containerClient = _blobServiceClient.GetBlobContainerClient(containerName);

    await foreach (var item in containerClient.GetBlobsAsync())
    {
        var blobClient = containerClient.GetBlobClient(item.Name);
        var blobProperties = await blobClient.GetPropertiesAsync();

        var blobInfo = new BlobInfo
        {
            ImageUri = blobClient.Uri.ToString(),
            ThumbnailUri = blobClient.Uri.ToString().Replace("/photos/", "/thumbnails/"),
            Caption = blobProperties.Value.Metadata.ContainsKey("Caption") ? blobProperties.Value.Metadata["Caption"] : item.Name
        };

        foreach (var key in blobProperties.Value.Metadata.Keys.Where(k => k.StartsWith("Tag")))
        {
            blobInfo.Tags.Add(blobProperties.Value.Metadata[key]);
        }

        blobs.Add(blobInfo);
    }

    return blobs;
}

Attempts to Resolve: I have verified that the BlobInfo class is properly compiled and that the Tags property is public and included in the class definition. The issue persists even after cleaning and rebuilding the solution. I suspect there might be a namespace mismatch or a project setup issue that I am overlooking.

Request: Could you please assist me in identifying the cause of this error and suggest a solution? Your guidance on this matter would be greatly appreciated.

Thank you for your time and assistance.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,963 questions
Azure Computer Vision
Azure Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
388 questions
0 comments No comments
{count} votes

Accepted answer
  1. SAMITSARKAR_MSFT 791 Reputation points Microsoft Employee
    2023-11-11T05:51:24.1066667+00:00
    Welcome to the Microsoft Q&A Platform. Thank you for reaching out, and I hope you are doing well.
    
    The error message suggests that the compiler cannot find a definition for the property or method named 'Tags' on the type 'BlobInfo'. I have tried reproducing the issue with the same code shared by using a single namespace in a console application (Refer Inline), but it seems like this issue cannot be reproduced as the structure shared is correct. Looking at the behavior, I am speculating an issue with the with code version reference mismatch.
    
    //Save as BlobInfo.cs
    using System.Collections.Generic;
    namespace ConsoleApp1
    {
         public class BlobInfo
        {
            public string ImageUri { get; set; }
            public string ThumbnailUri { get; set; }
            public string Caption { get; set; }
            public List<string> Tags { get; set; } = new List<string>();
        }
    }
    
    //Save as Program.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Azure.Storage.Blobs;
    using Azure.Storage.Queues;
    
    namespace ConsoleApp1
    {
        internal class Program
        {
            static string connectionString = "";
            public static void Main(string[] args)
            {
    		ListBlobsWithMetadataAsync("test");
    	}
    
            public static List<BlobInfo> ListBlobsWithMetadataAsync(string containerName)
            {
    	    BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
                List<BlobInfo> blobs = new List<BlobInfo>();
                BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
                 foreach (var item in containerClient.GetBlobs())
                {
                    var blobClient = containerClient.GetBlobClient(item.Name);
                    var blobProperties =  blobClient.GetProperties();
                    var blobInfo = new BlobInfo
                    {
                        ImageUri = blobClient.Uri.ToString(),
                        ThumbnailUri = blobClient.Uri.ToString(),
                        Caption = blobProperties.Value.Metadata.ContainsKey("Caption") ? blobProperties.Value.Metadata["Caption"] : item.Name
                    };
    
                    foreach (var key in blobProperties.Value.Metadata.Keys.Where(k => k.StartsWith("Tag")))
                    {
                        blobInfo.Tags.Add(blobProperties.Value.Metadata[key]);
                    }
    
                    blobs.Add(blobInfo);
                }
    
                return blobs;
            }
        }   
    }
    
    
    Thanks
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.