Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type Boolean

Viewed 1584

How do I fix this ? :/

public static async Task<bool> Run([QueueTrigger("<queueNameHere", Connection = "<connectionHere>")]byte[] myQueueItem, TraceWriter log)

Results in the error:

Microsoft.Azure.WebJobs.Host: Error indexing method 'Run'. 
Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type
Boolean&. 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.).
2 Answers

The error stems from the fact that you are trying to set the return type as a Boolean (Task) and I believe QueueTriggered functions can only have a return type of void. So just remove the return type:

public static async Task Run(...)

Was there a specific purpose in your attempt to have a return type? If you are trying to convey status to another process, then you should consider an alternate method, such as placing a completed message on another queue via output binding or updating a status in a DB, etc.

The return type is used to set the function return type, return is when you use return property to bind the out put.

In the official doc, there is a description about how to set the return type in the queue trigger function.

Usage:

Write a single queue message by using a method parameter such as out T paramName. You can use the method return type instead of an out parameter, and T can be any of the following types:

  • An object serializable as JSON
  • string
  • byte[]
  • CloudQueueMessage

If you try to bind to CloudQueueMessage and get an error message, make sure that you have a reference to the correct Storage SDK version.

In C# and C# script, write multiple queue messages by using one of the following types:

  • ICollector or IAsyncCollector
  • CloudQueue

So all support type is listed there, so you have to use other type to bind, you oculd refer to my below code.

public static class Function1
    {
        [FunctionName("Function1")]
        [return: Queue("queue")]
        public static async Task<CloudQueueMessage> Run([QueueTrigger("myqueue", Connection = "AzureWebJobsStorage")]WorkItem input, ILogger log)
        {
            string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
            log.LogInformation($"C# script processed queue message. Item={json}");
            CloudQueueMessage message = new CloudQueueMessage("test message");
            return message;
        }

        public class WorkItem
        {
            public string Id { get; set; }
        }

    }

I use a queue trigger function to get the json data from the myqueue and send a queue message to queue.

enter image description here

Related