Question

I've just updated (from v3.x) to the latest version of AttributeRouting on my WebAPI project and it's just started to produce errors I've never seen before.

Now whenever a call is made to the API I get an error like this:

System.InvalidOperationException: The constraint entry 'inboundHttpMethod' on the route with route template 'my/path' must have a string value or be of a type which implements 'IHttpRouteConstraint'.
   at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
   at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
   at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)
   at AttributeRouting.Web.Http.Framework.HttpAttributeRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request)
   at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)
   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
   at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context)
   at System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

It's been working without issues for months.

Non of the docs detail there are any usage changes. My config file looks correct.

What has gone wrong? I can't find anyone else reporting this.

Was it helpful?

Solution

Definitely in memory hosting type issue. Recently, I encounter the same issue after updating to MVC 5. I looked on various posts and actually found one that ultimately helped me out. Here is how I solved this.

After installing library for Attribute routing, you must have the following in global.ascx file.

AttributeRoutingHttpConfig.RegisterRoutes(GlobalConfiguration.Configuration.Routes);

In AttributeRoutingHttpConfig class, replace the following code:

routes.MapHttpAttributeRoutes();

with

routes.MapHttpAttributeRoutes(cfg =>
{
            cfg.InMemory = true;
            cfg.AutoGenerateRouteNames = true;
            cfg.AddRoutesFromAssemblyOf<ANY_API_Controller>();
        });

Here, ANY_API_Controller refers to any of your apicontroller class from your project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top