U4-5384 - Custom ApiController routes not working after upgrade to 7.1.5

Created by Tom Fulton 22 Aug 2014, 05:24:27 Updated by Tom Fulton 27 Aug 2014, 04:44:39

Relates to: U4-5407

Relates to: U4-5151

I typically register custom routes for ApiControllers in the OnApplicationStarted event, something like this:

RouteTable.Routes.MapHttpRoute( "someApi", "Api/Something/", new );

After upgrading from 7.1.3 to 7.1.5, I get the following error when trying to access a method via the custom route (works fine via the normal /Umbraco/Api/etc route)

{ Message: "An error has occurred.", ExceptionMessage: "Object reference not set to an instance of an object.", ExceptionType: "System.NullReferenceException", StackTrace: " at Umbraco.Web.WebApi.NamespaceHttpControllerSelector.SelectController(HttpRequestMessage request) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken) at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)" }

I believe this was caused by [this commit|https://github.com/umbraco/Umbraco-CMS/commit/8e7ed865f07dfeee939fb144f5ba4d1808f1328c]. Debugging shows me that routeData.Route.DataTokens is null when I access it from the custom route ([this line|https://github.com/umbraco/Umbraco-CMS/commit/8e7ed865f07dfeee939fb144f5ba4d1808f1328c#diff-a1fccac1af4ba6b352e4c8c75f419d7aR28]).

To workaround this, I added this line to my app's OnApplicationStarted event, which I think basically reverts what was done in the above commit.

GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector), new DefaultHttpControllerSelector(GlobalConfiguration.Configuration));


Tom Fulton 22 Aug 2014, 05:25:47

Believe the fix for U4-5151 spawned U4-5384

Shannon Deminick 25 Aug 2014, 06:21:04

Was missing a null check, unfortunately the WebApi routing helper methods don't set everything up like the MVC ones and it doesn't assign DataTokens to an instance of anything so it remains null unless you explicitly assign it.

Fixed in rev: 39987d5f7d730af5a5ca868dcfaf258a51f06a3c

Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category: Architecture

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.1.5

Due in version: 7.1.6


Story Points: