Azure / Azure/azure-functions-host
Unable to use "guid" as an HttpTrigger route parameter (Invalid cast from 'System.String' to 'System.Guid')
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
When trying to pass a guid as a parameter binding within a route definition the following exception is thrown
`Exception while executing function: TestParams -> One or more errors occurred. -> Exception binding parameter 'req' -> Invalid cast from 'System.String' to 'System.Guid'.`
#### Investigative information
Please provide the following:
- Timestamp: 2018-06-07T11:27:47.578
- Function App version (1.0 or 2.0-beta): 1.0.12.1
- Function App name: vos6functiondev
- Function name(s) (as appropriate): GetPendingDamages
- Invocation ID: (requestid): 65ead198-8c37-438d-b9a5-ac17165f1e41
- Region: UK West
#### Repro steps
Provide the steps required to reproduce the problem:
- For an HttpTrigger, configure a route parameter binding for a Guid
```
[FunctionName("GetPendingDamages")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetPendingDamages/{stayId:guid}")]
HttpRequestMessage req,
Guid stayId,
TraceWriter log)
{...}
```
- Invoke the fuction as a GET request
- The following exception will be thrown
` "message": "Exception while executing function: TestParams -> One or more errors occurred. -> Exception binding parameter 'req' -> Invalid cast from 'System.String' to 'System.Guid'.",`
#### Expected behavior
Provide a description of the expected behavior.
I would expect to either
- have a valid Guid value available as an input parameter
- receive a 400 Bad Request, in case the value could not be parsed as a Guid
#### Known workarounds
Provide a description of any known workarounds.
You can do a `Guid.TryParse()` in code, but it would be nice to be able to have the Guid bindings available like in Web API 2
as it has been reported here
http://dontcodetired.com/blog/post/Dynamic-Binding-in-Azure-Functions-with-Imperative-Runtime-Bindings
and here https://stackoverflow.com/questions/46743180/is-attribute-routing-possible-in-azure-functions
Thanks :)
Contributor guide
Assessment
This issue has not been assessed yet.