You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
Having an incorrect route for action methods will throw misleading exception message.
Steps to reproduce:
Create a new ASP.NET Core web project with WebAPI template
Run the app the and ValuesController will work as excpected
Add a regex(\\d+)' constraint to theidparameter of theValuesController.Get` method
Run the app and it works just as expected
Mistakenly add an incorrect route config like the below one (consider the extra double colon after regex)
[HttpGet("{id:regex:(\\d+)}")]
public string Get(int id)
{
return $"The content for document #{id}";
}
Run the app again and you will see the following misleading exception:
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 DEBUG http://localhost:13367/ 0
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:13367/api/values
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 93.9806ms 200
Microsoft.AspNetCore.Server.Kestrel:Error: Connection id "0HKT7OA7R93TP": An unhandled exception was thrown by the application.
System.MissingMethodException: No parameterless constructor defined for this object.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.AspNetCore.Routing.DefaultInlineConstraintResolver.CreateConstraint(Type constraintType, String argumentString)
at Microsoft.AspNetCore.Routing.DefaultInlineConstraintResolver.ResolveConstraint(String inlineConstraint)
at Microsoft.AspNetCore.Routing.RouteConstraintBuilder.AddResolvedConstraint(String key, String constraintText)
at Microsoft.AspNetCore.Routing.Tree.TreeRouteBuilder.MapOutbound(IRouter handler, RouteTemplate routeTemplate, RouteValueDictionary requiredLinkValues, String routeName, Int32 order)
at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.AddEntries(TreeRouteBuilder builder, ActionDescriptorCollection actions)
at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.GetTreeRouter()
at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.RouteAsync(RouteContext context)
at Microsoft.AspNetCore.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 295.4269ms 200
Ideal: To have a design time route config checking
Normal: To have an exception message like this: An unhandled exception was thrown while constructing the route config for ValuesController.Get method. No parameterless constructor defined for regex:
At first I thought the problem was with my models so I commented here in DI repo.
The text was updated successfully, but these errors were encountered:
I'm not really sure what's up with the RegexRouteConstraint that's causing this issue.
In general though we should try to surface this error in a better way. We did a lot of work to collect most of the errors that can be thrown from attribute routing into a single group so that you can see all of the errors at once and not just the first one. It looks like we missed the case where a constraint throws.
Having an incorrect route for action methods will throw misleading exception message.
Steps to reproduce:
regex(\\d+)' constraint to the
idparameter of the
ValuesController.Get` methodregex
)project.json
Expected Behavior
An unhandled exception was thrown while constructing the route config for ValuesController.Get method. No parameterless constructor defined for regex:
At first I thought the problem was with my models so I commented here in DI repo.
The text was updated successfully, but these errors were encountered: