Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeRouting WebAPI Now Producing Errors

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.

like image 930
Jammer Avatar asked Jun 07 '26 13:06

Jammer


1 Answers

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.

like image 74
prashantchalise Avatar answered Jun 09 '26 03:06

prashantchalise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!