5

I am trying to use [FromQuery] with Azure Function v3 but I am getting the following error:

Cannot bind parameter 'search' to type String.

For the following method:

[FunctionName("GetObjects")]
public ActionResult<IActionResult> QueryObjects(
    [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "objects")]
    HttpRequest req,
    ILogger log,
    [FromQuery] string search = null)
{
    //do some stuff
}

Is [FromQuery] not supported?

Should I use req.Query["search"] to get the query parameter?

From functions.desp.json

Related to binding

"Microsoft.Extensions.Configuration.Binder/3.1.1": {
    "dependencies": {
        "Microsoft.Extensions.Configuration": "3.1.2"
    },
    "runtime": {
        "lib/netcoreapp3.1/Microsoft.Extensions.Configuration.Binder.dll": {
        "assemblyVersion": "3.1.1.0",
        "fileVersion": "3.100.119.61404"
        }
    }
},

KyleMit
  • 30,350
  • 66
  • 462
  • 664
doorman
  • 15,707
  • 22
  • 80
  • 145

2 Answers2

3

This is what you face now:

enter image description here

Method signatures developed by the azure function C # class library can include these:

ILogger or TraceWriter for logging (v1 version only)

A CancellationToken parameter for graceful shutdown

Mark input and output bindings by using attribute decoration

Binding expressions parameters to get trigger metadata

From this doc, it seems that it is not supported. You can create your custom binding like this, and dont forget to register it in the startup.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
3

If you want to bind it directly, it's not possible. So you could try to change your route like Function1/name={name}&research={research} then bind it to string parameter.

Below is my test code:

[FunctionName("Function1")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route="Function1/name={name}&research={research}")] HttpRequest req,
    String name,
    String research,
    ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");
    log.LogInformation(research);
    
    string responseMessage = $"Hello, {name}. This HTTP triggered function executed successfully.";

    return new OkObjectResult(responseMessage);
}

screenshot

KyleMit
  • 30,350
  • 66
  • 462
  • 664
George Chen
  • 13,703
  • 2
  • 11
  • 26