azurefunction error

SOUBHAGYA PATRA 1 Reputation point
2021-07-25T17:01:37.003+00:00

Hi,
I am creating a azurefunction ( <AzureFunctionsVersion>v3</AzureFunctionsVersion>),
my requirement is to read data from topic and saved into cosmoDB,
when I am trying to add (IAsyncCollector<Rawmessage> cosmodbCollector)this cosmodb collector,
it giving below error on local,

Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'cosmodbCollector' to type IAsyncCollector`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

please help

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,003 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jaliya Udagedara 2,821 Reputation points MVP
    2021-07-26T00:26:00.24+00:00

    Can you share the code please? From the code you have shared, hard to say what it is. But about the error message, make sure you have the latest required NuGet packages installed.

    From your question, what it sounds like is you need to have an Azure Service Bus triggered function and an Output binding for Cosmos DB.

    You can read through the following for very detailed steps.

    Azure Service Bus trigger for Azure Functions
    Azure Cosmos DB output binding for Azure Functions 2.x and higher

    0 comments No comments

  2. SOUBHAGYA PATRA 1 Reputation point
    2021-07-26T04:40:02.463+00:00

    Hi ,
    Please find my code below,
    when I am trying to run this on local then it giving below error message on the console,

    [FunctionName("Function1")]
    public async Task Run([ServiceBusTrigger("%AuditScanTopic%","%AuditSubscriptionName%",
    Connection = "AuditConnectionString")]Message enqueueMessage, MessageReceiver messageReceiver,
    string lockToken, IAsyncCollector<Rawmessage> cosmodbCollector,
    ILogger log)
    {
    log.LogInformation($"C# ServiceBus topic trigger function processed message: {lockToken}");
    await messageReceiver.CompleteAsync(lockToken);

        }
    

    this is NuGet package reference,
    <ItemGroup>
    <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.2.1" />
    <PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.10" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.4" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    </ItemGroup>

    error message-
    Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'cosmodbCollector' to type IAsyncCollector`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

    Please suggest.

    0 comments No comments

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.