I’m trying to make an example of BlobTrigger Azure Function using Visual Studio Code.
For that I was following along the Book "Beginning Azure Functions" of Rahul Sawhney.
My csproj file is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<RootNamespace>blob_trigger</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
My Function class is:
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace AzureFunctionV2Book.Function
{
public static class BlobTriggerCSharp
{
[FunctionName("BlobTriggerCSharp")]
public static async Task Run([BlobTrigger("image-blob/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, [Blob("output-blob/{name}", FileAccess.ReadWrite, Connection ="AzureWebJobsStorage")] CloudBlockBlob outputBlob, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blobn Name:{name} n Size: {myBlob.Length} Bytes");
var width = 100;
var height = 200;
var encoder = new PngEncoder();
using (var output = new MemoryStream())
using (Image<Rgba32> image = (Image<Rgba32>)Image.Load(myBlob)) {
image.Mutate(x => x.Resize(width, height));
image.Save(output, encoder);
output.Position = 0;
await outputBlob.UploadFromStreamAsync(output);
}
}
}
}
My local.settings.json file is:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=buildingazurefunctionsfr;AccountKey=somekey;EndpointSuffix=core.windows.net",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"FUNCTIONS_EXTENSION_VERSION": "~4",
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "DefaultEndpointsProtocol=https;AccountName=buildingazurefunctionsfr;AccountKey=somekey;EndpointSuffix=core.windows.net",
"WEBSITE_CONTENTSHARE": "building-azure-functions-fromvscodebed7b8",
"WEBSITE_RUN_FROM_PACKAGE": "1",
"APPINSIGHTS_INSTRUMENTATIONKEY": "app-key"
}
}
When I try to run the code, I get the following error:
[2023-10-20T15:17:59.993Z] A host error has occurred during startup operation ‘f67d9178-3d34-43ab-8715-a2a55f227595’.[2023-10-20T15:17:59.998Z] System.Private.CoreLib: Exception has been thrown by the target of an invocation. Microsoft.Azure.WebJobs.Extensions.Storage.Queues: Could not load type ‘Microsoft.Azure.WebJobs.ParameterBindingData’ from assembly ‘Microsoft.Azure.WebJobs, Version=3.0.34.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.
Value cannot be null. (Parameter ‘provider’)
Any idea how to solve it?
2
Answers
WORKING CODE
And the host.json is
}
I was getting the same error when I tried with the configuration with versions
[3.0.0, 4.0.0)
and[4.*, 5.0.0)
:host.json
to fix the above issue:Code Snippet:
Uploading Image to Container:
Output:
Updating answer as per the comments:
I was also getting the same error:
Microsoft.Azure.Storage.Blob(deprecated package)
.I have reproduced the same using your code with few modifications as shown below:
Code Snippet: