Azure-webjobs-sdk: [V2] Cannot create ServiceBusTrigger; 'Error indexing Method' exception

Created on 22 May 2018  Â·  2Comments  Â·  Source: Azure/azure-webjobs-sdk

I'm trying to use the ServiceBusTrigger within a V2 Azure Function and getting an exception where I would expect it to work just fine based on usage shown in the docs.

Repro steps

  1. Create a new HttpTrigger Azure Function
  2. Swap out the HttpTrigger for a ServiceBusTrigger, like so:
public static async System.Threading.Tasks.Task<IActionResult> RunAsync(
    [ServiceBusTrigger(@"messages", Connection = @"ServiceBusManageConnection")]MessageModel msg,
    TraceWriter log)
{

where MessageModel just looks like:

public class MessageModel
{
    public string Key { get; set; }
    public object Data { get; set; }
}
  1. Hit F5

Expected behavior

The Function is indexed and waits for a message from the specified Service Bus queue

Actual behavior

An exception is thrown:
~
[5/22/2018 7:18:15 PM] Error indexing method 'Function1.RunAsync'
[5/22/2018 7:18:15 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.RunAsync'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type IActionResult&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
~

Known workarounds

Haven't found any yet.

Related information

  • vs2017.15.7.2
  • Functions Extension v15.0.40502
  • Nuget pkg v1.0.13
  • ServiceBus nuget pkg v3.0.0-beta5

Other attempts

  • I tried removing my custom class (MessageModel) from the equation and just make the trigger give a string object but that had the same result.
  • I tried downgrading the previous nupkg for ServiceBus (3.0.0-beta4) (and therefore Functions nupkg 1.0.10 due to dependency mismatches) and got an error saying serviceBusTrigger wasn't even supported:
    ~
    [5/22/2018 7:38:01 PM] Function1: The binding type 'serviceBusTrigger' is not registered. Please ensure the type is correct and the binding extension is installed.
    ~

Addtional remarks

This error message is especially confusing for Functions developers; there's nowhere (readily available) to play with config. so it leads one down a rabbit hole of web searches all pertaining to WebJobs; we should improve this.

Most helpful comment

After reviewing more docs, I found the return type of a ServiceBusTrigger function should be void (or Task) and not IActionResult or something else.

I think we could improve that error message. It's also still curious that -beta4 of the SB package just refused to acknowledge the trigger at all. ¯\_(ツ)_/¯

All 2 comments

I changed my code over to a V1 function and was immediately met with:
~
[5/22/2018 7:51:09 PM] The following 2 functions are in error:
[5/22/2018 7:51:09 PM] RunAsync: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.RunAsync'. Microsoft.ServiceBus: ConnectionString used to create MessagingFactory shouldn't include EntityPath as MessagingFactory is at Namespace level.
~

Which led me to remove this from my Connection String value (essentially meaning create my SAS key from the 'Queues' area of my SB instance, not the actual queue). After doing this, the v1 Function gave an error similar to the v2 function:
~
[5/22/2018 7:54:14 PM] The following 1 functions are in error:
[5/22/2018 7:54:14 PM] RunAsync: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.RunAsync'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type HttpResponseMessage&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
~

but I went back to the v2 function and changed my connection strings to see if it would help matters any. it didn't.

After reviewing more docs, I found the return type of a ServiceBusTrigger function should be void (or Task) and not IActionResult or something else.

I think we could improve that error message. It's also still curious that -beta4 of the SB package just refused to acknowledge the trigger at all. ¯\_(ツ)_/¯

Was this page helpful?
0 / 5 - 0 ratings