1

Resolved

Attribute-based routing is broken when used in same project as ODataServer

description

The reason is that EntityRepositoryControllerSelector isn't entirely compatible with attribute routing - due to no controller name - more info: http://wildermuth.com/2013/11/12/Web_API_2_s_Attribute_Routing_Looking_Deeper

Consequently the attribute routes aren't returned from the ControllerSelector.

There's also an initialization exception thrown if config.MapHttpAttributeRoutes() is called before adding the EntitySet controllers:
[InvalidOperationException: ValueFactory attempted to access the Value property of this instance.]
   System.Lazy`1.CreateValue() +416
   System.Lazy`1.LazyInitValue() +152
   System.Lazy`1.get_Value() +75
   System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping() +53
   EntityRepository.ODataServer.Routing.EntityRepositoryControllerSelector.GetControllerMapping() in c:\devtools\teamcity\BuildAgent\work\a1dac9440314bb7\src\ODataServer\Routing\EntityRepositoryControllerSelector.cs:108
   System.Web.Http.Routing.AttributeRoutingMapper.AddRouteEntries(SubRouteCollection collector, HttpConfiguration configuration, IInlineConstraintResolver constraintResolver) +102
   System.Web.Http.Routing.<>c__DisplayClass4.<MapAttributeRoutes>b__1() +111
   System.Web.Http.Routing.RouteCollectionRoute.EnsureInitialized(Func`1 initializer) +83
   System.Web.Http.Routing.<>c__DisplayClass2.<MapAttributeRoutes>b__0(HttpConfiguration config) +169
   System.Web.Http.HttpConfiguration.ApplyControllerSettings(HttpControllerSettings settings, HttpConfiguration configuration) +179
   System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type) +305
   System.Web.Http.Controllers.HttpControllerDescriptor.InvokeAttributesOnControllerType(HttpControllerDescriptor controllerDescriptor, Type type) +137
   System.Web.Http.Controllers.HttpControllerDescriptor.Initialize() +60
   System.Web.Http.Controllers.HttpControllerDescriptor..ctor(HttpConfiguration configuration, String controllerName, Type controllerType) +266
   System.Web.Http.Dispatcher.DefaultHttpControllerSelector.InitializeControllerInfoCache() +627
   System.Lazy`1.CreateValue() +416
   System.Lazy`1.LazyInitValue() +152
   System.Lazy`1.get_Value() +75
   System.Web.Http.Dispatcher.DefaultHttpControllerSelector.GetControllerMapping() +53
   EntityRepository.ODataServer.Routing.EntityRepositoryControllerSelector.GetFallbackControllerMapping() in c:\devtools\teamcity\BuildAgent\work\a1dac9440314bb7\src\ODataServer\Routing\EntityRepositoryControllerSelector.cs:84
   EntityRepository.ODataServer.ODataServerConfigurer.AddStandardEntitySetControllers(ControllerTypeSelector controllerTypeSelector) in c:\devtools\teamcity\BuildAgent\work\a1dac9440314bb7\src\ODataServer\ODataServerConfigurer.cs:139
   PD.Web.DemandFinder.WebApiConfig.ConfigureODataService(HttpConfiguration config) in c:\src\code\Web\DemandFinder\trunk\src\Web\App_Start\WebApiConfig.cs:48
   PD.Web.DemandFinder.WebApiConfig.Register(HttpConfiguration config) in c:\src\code\Web\DemandFinder\trunk\src\Web\App_Start\WebApiConfig.cs:33
   System.Web.Http.GlobalConfiguration.Configure(Action`1 configurationCallback) +124
   PD.Web.DemandFinder.Global.Application_Start(Object sender, EventArgs e) in c:\src\code\Web\DemandFinder\trunk\src\Web\Global.asax.cs:24

[HttpException (0x80004005): ValueFactory attempted to access the Value property of this instance.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9905689
   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) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): ValueFactory attempted to access the Value property of this instance.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9885044
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

comments

johncrim wrote Feb 19, 2014 at 8:00 PM

Fixed.