Pawel Maga Pawel Maga - 2 months ago 18
C# Question

Azure functions: Cannot bind parameter '_return' to type HttpResponseMessage

I created basic Azure function from the quickstart guide. In accordance with tutorial, this default function should work instantly, but I get an error.

Function body:

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
log.Info("C# HTTP trigger function processed a request.");

// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)

// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();

// Set name to query string or body data
name = name ?? data?.name;

return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);

Error message:

Function ($HttpTriggerCSharp1) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HttpTriggerCSharp1'. 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.).

I cannot find any startup code for this functions and I think there is some configuration option to set which I don't know.


You can fix this for now by changing the name of your response output binding from $return to res. The former will work soon in our next release, but doesn't yet. It looks like we rolled out a Function template update a little too early for this one - I've created a bug here in our repo for that issue. Thanks :)