Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routeData.As<Guid>("id") thrown Invalid cast exception #106

Closed
sonerturkkan opened this issue May 10, 2018 · 3 comments · Fixed by #107
Closed

routeData.As<Guid>("id") thrown Invalid cast exception #106

sonerturkkan opened this issue May 10, 2018 · 3 comments · Fixed by #107

Comments

@sonerturkkan
Copy link

this.Get("/stock/{id:guid}", async (req, res, routeData) =>
{
     var myid = routeData.As<Guid>("id");  //thrown Invalid cast exception
     await res.Negotiate(myid);
});

There has been an error
System.InvalidCastException: Invalid cast from 'System.String' to 'System.Guid'.
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at coster.api.ExRouteDataExtensions.AsGuid(RouteData routeData, String key) in
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Carter.CarterExtensions.<>c__DisplayClass1_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d__6.MoveNext()

@JoeStead
Copy link
Collaborator

Under the hood, it uses Convert.ChangeType, which apparently doesn't support guids. Would be keen to avoid adding in special clauses into the conversion logic, I wonder if something like: https://stackoverflow.com/a/393787/1324810 would work

@jchannon
Copy link
Member

jchannon commented May 10, 2018 via email

@jchannon
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants