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.
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; }
}
The Function is indexed and waits for a message from the specified Service Bus queue
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.).
~
Haven't found any yet.
MessageModel) from the equation and just make the trigger give a string object but that had the same result.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.
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. ¯\_(ツ)_/¯
Most helpful comment
After reviewing more docs, I found the return type of a
ServiceBusTriggerfunction should bevoid(orTask) and notIActionResultor something else.I think we could improve that error message. It's also still curious that
-beta4of the SB package just refused to acknowledge the trigger at all. ¯\_(ツ)_/¯