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'.
Please provide the following:
Provide the steps required to reproduce the problem:
[FunctionName("GetPendingDamages")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetPendingDamages/{stayId:guid}")]
HttpRequestMessage req,
Guid stayId,
TraceWriter log)
{...}
"message": "Exception while executing function: TestParams -> One or more errors occurred. -> Exception binding parameter 'req' -> Invalid cast from 'System.String' to 'System.Guid'.",Provide a description of the expected behavior.
I would expect to either
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 :)
I've also noticed that the same exception is thrown when binding to a custom POCO in the http request body.
If the POCO contains any Guid params, the binder will fail to parse them as such from the JSON in the payload
We have tracking item here https://github.com/Azure/azure-functions-host/issues/2279 to preserve constraint types in the route. Closing this as dup.
Please reopen this as this is Guid as a parameter in the URL, not a Guid in the poco.
Is there any update to fixing this issue short of using workarounds? The issue is still present with the following configuration.
Visual Studio 2019 (16.0.0)
.NET Core 2.2
Azure Functions Core Tools (2.5.553 Commit hash: b63f2d6f5479718ca276f7b585a8cc6b9bc57c4f)
Function Runtime Version: 2.0.12382.0
I'm going to reopen this because after investigation, it looks like #2279 is unrelated.
Most helpful comment
Please reopen this as this is Guid as a parameter in the URL, not a Guid in the poco.