I have MVC Attribute routing enabled alongside Convention routing. I get this error every time I run the application.
The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.
Here is the stack trace:
[InvalidOperationException: The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.]
System.Web.Mvc.Routing.InlineRouteTemplateParser.GetInlineConstraint(Group constraintGroup, Boolean isOptional, IInlineConstraintResolver constraintResolver) +389
System.Web.Mvc.Routing.InlineRouteTemplateParser.ParseRouteTemplate(String routeTemplate, IDictionary2 defaults, IDictionary
2 constraints, IInlineConstraintResolver constraintResolver) +488
System.Web.Mvc.Routing.DirectRouteFactoryContext.CreateBuilder(String template, IInlineConstraintResolver constraintResolver) +308
System.Web.Mvc.Routing.DirectRouteFactoryContext.CreateBuilderInternal(String template) +48
System.Web.Mvc.Routing.DirectRouteFactoryContext.CreateBuilder(String template) +44
System.Web.Mvc.RouteAttribute.System.Web.Mvc.Routing.IDirectRouteFactory.CreateRoute(DirectRouteFactoryContext context) +80
System.Web.Mvc.Routing.DefaultDirectRouteProvider.CreateRouteEntry(String areaPrefix, String controllerPrefix, IDirectRouteFactory factory, IReadOnlyCollection1 actions, IInlineConstraintResolver constraintResolver, Boolean targetIsAction) +115
1 factories, IReadOnlyCollection
System.Web.Mvc.Routing.DefaultDirectRouteProvider.CreateRouteEntries(String areaPrefix, String controllerPrefix, IReadOnlyCollection1 actions, IInlineConstraintResolver constraintResolver, Boolean targetIsAction) +155
1 factories, IInlineConstraintResolver constraintResolver) +188
System.Web.Mvc.Routing.DefaultDirectRouteProvider.GetActionDirectRoutes(ActionDescriptor actionDescriptor, IReadOnlyList
System.Web.Mvc.Routing.DefaultDirectRouteProvider.GetDirectRoutes(ControllerDescriptor controllerDescriptor, IReadOnlyList1 actionDescriptors, IInlineConstraintResolver constraintResolver) +245
1 controllerTypes, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider) +234
System.Web.Mvc.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, IEnumerable
System.Web.Mvc.Routing.AttributeRoutingMapper.MapAttributeRoutes(RouteCollection routes, IEnumerable`1 controllerTypes, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider) +333
System.Web.Mvc.Routing.AttributeRoutingMapper.MapAttributeRoutes(RouteCollection routes, IInlineConstraintResolver constraintResolver, IDirectRouteProvider directRouteProvider) +398
System.Web.Mvc.Routing.AttributeRoutingMapper.MapAttributeRoutes(RouteCollection routes, IInlineConstraintResolver constraintResolver) +192
System.Web.Mvc.RouteCollectionAttributeRoutingExtensions.MapMvcAttributeRoutes(RouteCollection routes) +123
SocialManager.RouteConfig.RegisterRoutes(RouteCollection routes) in c:\Users\Naser Dostdar\Documents\Visual Studio 2013\Projects\SocialManager\SocialManager\App_Start\RouteConfig.cs:16 SocialManager.MvcApplication.Application_Start() in c:\Users\Naser Dostdar\Documents\Visual Studio 2013\Projects\SocialManager\SocialManager\Global.asax.cs:18[HttpException (0x80004005): The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9942821
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +352
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296[HttpException (0x80004005): The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9924184 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +261
And here is how my Route.Config file looks like:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(null, "Page{page}",
new
{
controller = "Blogs",
action = "Index",
category =
(string)null
},
new { page = @"\d+" }
);
routes.MapRoute(null,
"{category}",
new { controller = "Blogs", action = "Edit", page = 1 }
);
routes.MapRoute(null,
"{category}/Page{page}",
new { controller = "Blogs", action = "List" },
new { page = @"\d+" }
);
routes.MapRoute(null, "{controller}/{action}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
P.S: I did not defined any MVC Attribute route in my project as of yet, just want to test enabling the MVC Attribute routing feature.
Web API Version : 2.2
Somewhere you have defined an attribute route. Nothing else will cause this error. Where you've done that, you've used string
as a route constraint. For example:
[Route("{foo:string}")]
However, string
is not a valid route constraint, as everything in a route is a string. Long and short, find the route attribute(s) you defined that include :string
and remove that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With