3

I'm trying to create an Azure Function that takes a wildcard route segment. However, when I try to include the wildcard segment as a method parameter I get the following error:

<ApiErrorModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Azure.WebJobs.Script.WebHost.Models">
<Arguments xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" i:nil="true"/>
<ErrorCode>0</ErrorCode>
<ErrorDetails>
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.Page --->
System.InvalidOperationException : Exception binding parameter 'path' ---> 
System.InvalidOperationException : No value was provided for parameter 'path'. 
at Microsoft.Azure.WebJobs.Host.Bindings.Invoke.ClassInvokeBinding`1.BindAsync(BindingContext context) 
at async Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync[TTriggerValue](ValueBindingContext context,Object value,IDictionary`2 parameters) 
End of inner exception at Microsoft.Azure.WebJobs.Host.Executors.DelayedException.Throw() 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,IReadOnlyDictionary`2 parameters,TraceWriter traceWriter,ILogger logger,CancellationTokenSource functionCancellationTokenSource) 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
End of inner exception at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) 
at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken) 
at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw() 
at async Microsoft.Azure.WebJobs.JobHost.CallAsyncCore(MethodInfo method,IDictionary`2 arguments,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary`2 arguments,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ProcessRequestAsync(HttpRequestMessage request,FunctionDescriptor function,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.<>c__DisplayClass3_0.<ExecuteAsync>b__0(??) 
at async Microsoft.Azure.WebJobs.Extensions.Http.HttpRequestManager.ProcessRequestAsync(HttpRequestMessage request,Func`3 processRequestHandler,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken) 
at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) 
at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) 
at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken) 
at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)
</ErrorDetails>
<Id>1efe3ac0-3f71-48a0-906e-e9410a214f5a</Id>
<Message>
Exception while executing function: Functions.Page -> Exception binding parameter 'path' -> No value was provided for parameter 'path'.
</Message>
<RequestId>9f6307a0-f9bd-4c41-9531-f6cef0ff6062</RequestId>
<StatusCode>InternalServerError</StatusCode>
</ApiErrorModel>

This is my function:

[FunctionName("Page")]

public static HttpResponseMessage Run(
  [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "{owner}/{repo}/page/{*path}")]
  HttpRequestMessage req, string owner, string repo, string path, TraceWriter log)
{
 // my code
}

I have found that if I omit the path parameter on the function the method is invoked, but then I don't have direct access to the wildcard segments.

Any ideas what might be wrong here? Is binding of a wildcard path unsupported in Azure Functions?

I do realize that I could just accept that the routing "works" in the sense that my function is invoked without a binding for the wildcard segment of the route; and do that binding myself in code, but if there is a simpler way to get this to work that would be really useful.

1

1 Answer 1

1

I know it is many years too late but if I have found my way here so might others. In Functions v2 it possible to define a route with parameters. For example:


public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "GET", Route="odata/{category:alpha}/{product:alpha}"]HttpRequest request, ILogger log, string category, string product)
{
    log.Log(LogLevel.Information, $"Request: {category}:{product}?{string.Join(",", request.QueryString)}")
}

There are rather more details in these articles here: https://jonathangiles.net/creating-custom-routes-in-azure-functions/ and here: https://learn.microsoft.com/en-us/sandbox/functions-recipes/routes?tabs=csharp

2
  • Thanks for taking the time to answer, but I can't see anything in those links that indicates that a wildcard path segment is supported. I want a {*foo} segment in the route to match all the remaining path segments, but all of the examples you've shown only match a single path segment. Is there another example of wildcard path matching you have seen?
    – Kal
    Oct 6, 2018 at 20:40
  • It is possible to make parameters optional, so a single function with many arguments, e.g. "\{a?}\{b?}\{c?}" could be used to capture all likely situations. Optional parameters are mentioned at the end of this article: learn.microsoft.com/en-us/sandbox/functions-recipes/… Oct 9, 2018 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.