0

I have Azure WebJobs methods registered as below

Program.cs

hostBuilder.ConfigureWebJobs(webJobsBuilder =>
{
    webJobsBuilder
        .AddTimers()
        .AddAzureStorageCoreServices()
        .AddAzureStorageQueues()
        .AddAzureStorageBlobs()
        .AddServiceBus();
});

UserFunctions.cs

[FunctionName("SendRegisteredUserVerificationEmailsServiceBusTrigger")]
public async Task SendRegisteredUserVerificationEmailsServiceBusTrigger([ServiceBusTrigger(BookStoreServiceBusQueueNames.RegisteredUsers, Connection = "AzureWebJobsServiceBusConnectionString", IsSessionsEnabled = false)]  Int32 deliveryCount,
    DateTime enqueuedTimeUtc, ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions)
{
...
}

I checked the code samples below: https://learn.microsoft.com/en-us/dotnet/api/overview/azure/microsoft.azure.webjobs.extensions.servicebus-readme-pre

And could not find a difference.

I am using following nuget packages:

  1. https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.ServiceBus/ https://www.nuget.org/packages/Azure.Messaging.ServiceBus/

I am getting following error:

InvalidOperationException: Cannot bind parameter 'message' to type 
ServiceBusReceivedMessage. 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.).

Am I missing something here?

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158

1 Answers1

1

though Its too late. still I would like to answer this so it will be helpful in future. Today, I faced the same error and I tried to compare the changes. one thing I notice was we shouldn't have the parameter to get the message properties such as enqueuedtime, delivery count, message body, etc. instead these are already available in ServiceBusReceivedMessage message. so below piece throws error at runtime, with the parameter

    [FunctionName("Function2")]
    public void Run([ServiceBusTrigger("testtopic", "testsub", Connection = "sbconnectionstring", AutoCompleteMessages = false)] string messageBody,
        ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions)
    {
        Console.WriteLine($"C# ServiceBus topic trigger function processed message: {messageBody}");
    }

and this one works fine. without properties param

    [FunctionName("Function2")]
    public void Run([ServiceBusTrigger("testtopic", "testsub", Connection = "sbconnectionstring", AutoCompleteMessages = false)]
        ServiceBusReceivedMessage message, ServiceBusMessageActions messageActions)
    {
        Console.WriteLine($"C# ServiceBus topic trigger function processed message: {message.Body}");
        messageActions.CompleteMessageAsync(message);
    }
threeleggedrabbit
  • 1,722
  • 2
  • 28
  • 60
  • 1
    This helped. Seems like in 5.8 version, MessageReceiver not binding, so ServiceBusMessageActions is need to do Deadletter with description. Also sserilizing the message body direct to a custom type along with binding ServiceBusReceivedMessage is not possible, only one or the other, but if wanting to manually Deadletter that requires ServiceBusReceivedMessage as argument. Slightly annoying as now need to put back in json deserilizer on functions for message.Body – Maze Oct 21 '22 at 13:44