Compatibility with ApiExplorer

May 7, 2015 at 8:52 PM
Hi Max,

I am trying to incorporate API documentation using Microsoft's ApiExplorer from the System.Web.Http.Description namespace. I can't get it to work with MvcCodeRouting.

You can reproduce the problem by adding the following code to the tail of a Global.Application_Start event handler and placing a breakpoint on it.

var api = GlobalConfiguration.Configuration.Services.GetApiExplorer().ApiDescriptions;

The descriptions are supposed to come from the registered routes. The description count returns 0 in my MvcCodeRouting projects even though there are 55 routes registered. As a sanity check I spun up a new default 4.5.1 Web Application, added the same line and it returns 1 route and 1 valid Descriptor as expected.

Also, a peculiarity I noticed while troubleshooting this issue is the following debug line returns the proper count of 55 routes in one of my MvcCodeRouting projects.

? GlobalConfiguration.Configuration.Routes.Count

But when I try to view GlobalConfiguration.Configuration.Routes.Last() in my immediate window I get an InvalidOperationException. The same troubleshooting test in the non-MvcCodeRouting project returns all route info as expected.

How to get these two (MvcCodeRouting and ApiExplorer) to work together?