2

I developed a simple VB .NET Web API project using .NET 4.5

This project was working perfectly fine, but I decided to install the AttributeRouting nuget package. After installing this package every function seems to raise the following exception:

The constraint entry 'inboundHttpMethod' on the route with route template 'Company' must have a string value or be of a type which implements 'IHttpRouteConstraint'.

In this message 'Company' is the route name to a simple GET method that simple returns one object. Every route results in this error message. The stacktrace is:

[InvalidOperationException: The constraint entry 'inboundHttpMethod' on the route with route template 'Company/{Id}' must have a string value or be of a type which implements 'IHttpRouteConstraint'.]
System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) +346 System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) +201
System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) +430
AttributeRouting.Web.Http.Framework.HttpAttributeRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) +250
System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext) +191
System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext) +233
System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +60
System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

I found the following thread which describes my problem: https://github.com/mccalltd/AttributeRouting/issues/191

Unfortunately, this fix does not seem to help: https://github.com/mccalltd/AttributeRouting/issues/191#issuecomment-13814025

Any ideas on how to fix this?

Jelle
  • 98
  • 1
  • 7

1 Answers1

1

In your case, I definitely feel like this issue is related with in memory hosting and do have a solution in the link that you mention above. After updating to MVC 5 I came across this issue and following the workout in this link which ultimately helped me out. Here is how I did it.

In global.ascx page, I have the following:

AttributeRoutingHttpConfig.RegisterRoutes(GlobalConfiguration.Configuration.Routes);

In AttributeRoutingHttpConfig class, I replaced the code

routes.MapHttpAttributeRoutes();

with

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

You can overwrite Your_API_Controller with any of your ApiController class. (Yes, don't know why but any api controller you want works ;) )

Hope this helps,

prashantchalise
  • 496
  • 1
  • 5
  • 12
  • That helped me thank you. Did you have to change this setting when your changed your hosting or pushed your application to production server? – kbo4sho88 May 14 '14 at 19:05