CodexBloom - Programming Q&A Platform

Azure Blob Storage - Unhandled Exception When Using Azure SDK for .NET 6 with Event Grid Trigger

👀 Views: 44 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-20
azure blob-storage azure-functions event-grid dotnet6 C#

I'm experimenting with Hey everyone, I'm running into an issue that's driving me crazy. I'm encountering an issue while trying to set up an Azure Function that is triggered by an Event Grid notification when a new blob is uploaded to Azure Blob Storage. My Azure Function is implemented in C# using .NET 6, and I'm leveraging the Azure SDK to process the blob data. However, I'm receiving an unhandled exception when the function is triggered, which states: `System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Azure.Storage.Common, Version=2.0.0.0'`. I've already ensured that the necessary NuGet packages are installed, specifically `Microsoft.Azure.WebJobs.Extensions.EventGrid` and `Microsoft.Azure.Storage.Blob`. Here's a snippet of my function code: ```csharp using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; using System.Threading.Tasks; public static class BlobEventHandler { [FunctionName("BlobEventHandler")] public static async Task Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log) { log.LogInformation($"Event received: {eventGridEvent.EventType}"); // Assume the event data contains the blob URL string blobUrl = eventGridEvent.Data?.GetType()?.GetProperty("url")?.GetValue(eventGridEvent.Data, null)?.ToString(); if (!string.IsNullOrEmpty(blobUrl)) { // Process the blob // This is where the exception occurs var blobServiceClient = new BlobServiceClient(blobUrl); var blobClient = blobServiceClient.GetBlobContainerClient("my-container").GetBlobClient("my-blob"); // Attempt to download the blob var downloadResponse = await blobClient.DownloadAsync(); } } } ``` I've checked the Azure Function App settings and ensured that the .NET runtime version is set to the correct version. Despite this, the issue persists. Is there a specific version of the Azure SDK or additional configuration that I might be missing? Any guidance on resolving this would be greatly appreciated. This is part of a larger API I'm building. Any pointers in the right direction? The project is a REST API built with C#. What am I doing wrong?