I'm having trouble getting this combination working, even in a hello world function. I want a function which consumes a table and blob, but not as triggers (trigger is timer).
When I run the function app locally I'm getting
Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Can't bind Blob to type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer'.
Possible causes:
1) Tried binding to 'Azure.Storage.Blobs.BlobContainerClient, Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
2) Tried binding to 'Microsoft.Azure.WebJobs.Extensions.Storage.Blobs.Config.BlobsExtensionConfigProvider MultiBlobContext, Microsoft.Azure.WebJobs.Extensions.Storage.Blobs, Version=5.0.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
3) Tried binding to 'System.IO.Stream, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
4) Tried binding to 'Azure.Storage.Blobs.Specialized.BlockBlobClient, Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
5) Tried binding to 'Azure.Storage.Blobs.Specialized.PageBlobClient, Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
6) Tried binding to 'Azure.Storage.Blobs.Specialized.AppendBlobClient, Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
7) Tried binding to 'Azure.Storage.Blobs.BlobClient, Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
8) Tried binding to 'Azure.Storage.Blobs.Specialized.BlobBaseClient, Azure.Storage.Blobs, Version=12.10.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' but user type assembly was 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, Microsoft.WindowsAzure.Storage, Version=9.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
To create this I did the following :
- Create new function app project using .NET 6.0 in process
- Created the following function :
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Table;
namespace FunctionApp1
{
public class Function1
{
[FunctionName("Function1")]
public void Run(
[TimerTrigger("0 */5 * * * *")] TimerInfo myTimer,
[Blob("activity-events", Connection = "StorageAccountBlobEndpoint")] CloudBlobContainer cloudBlobContainer,
ILogger log
)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
}
}
Complete CSPROJ is
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.5" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I want to have a table binding too in future which I understand precludes V 5.X of Microsoft.Azure.WebJobs.Extensions.Storage.
I'm probably missing something basic here but if anyone can identify would be appreciated.
CodePudding user response:
Are you looking at the blob and table to be output bindings since your input/trigger binding is a timer?
Take a look at this doc: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-output?tabs=in-process,extensionv5&pivots=programming-language-csharp
I believe something along the lines of:
public class Function1
{
[FunctionName("Function1")]
public void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
[Blob("activity-events", FileAccess.Write, Connection = "MyBlobConnString")] out Stream myblob,
ILogger log)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
//DO SOMETHING WITH myBlob before function exits
}
}
CodePudding user response:
OK as expected it seems to have turned out to be fairly simple - instead of referencing CloudBlobContainer
from Microsoft.WindowsAzure.Storage.Blob
, I switched to referencing it from Microsoft.Azure.Cosmos.Table
.
Side note : this unleashed an enormous pandora's box of other things I now need to fix in this existing solution.