I have a preexisting MVC app that I added Web API and Web API Self Documentation using Nuget. While the Web API controllers function fine (return valid responses to HTTP requests) the Help controller is not finding any Web API methods to document.
In the Help controller Index action "Configuration.Services.GetApiExplorer().ApiDescriptions" is returning with 0 results.
What populated ApiDescriptions and are there any config settings I need to set to expose my api to documentations?
The Help Area is a separate area from the rest of my application. Is this causing the piece that finds the Controllers to not find my controllers? Furthermore, I even added a help snipped to the HelpController itself, which still resulted in no API descriptions.
I do also have special routing for my API controllers, so I'm not sure if that's relevant.
I have the same problem and i don't use Glimpse and i solve the problem like this:
In the ProjectName\Areas\HelpPage\Controllers\HelpController.cs
file comment the constructors because is not called the implicit constructor public HelpController() : this(GlobalConfiguration.Configuration)
default is called the constructor with the parameter public HelpController(HttpConfiguration config)
and this initialization of the Configuration
property is incorect. And you cand solve this problem like this:
Solution 1: Comment/Remove the constructors.
public class HelpController : Controller
{
private const string ErrorViewName = "Error";
// public HelpController()
// : this(GlobalConfiguration.Configuration)
// {
// }
// public HelpController(HttpConfiguration config)
// {
// Configuration = config;
// }
/// <summary>
/// GlobalConfiguration By default
/// </summary>
protected static HttpConfiguration Configuration
{
get { return GlobalConfiguration.Configuration; }
}
public ActionResult Index()
{
ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
return View(Configuration.Services.GetApiExplorer().ApiDescriptions);
}
....
Solution 2: inject the default constructor by add this attribute [InjectionConstructor].
public class HelpController : Controller
{
private const string ErrorViewName = "Error";
[InjectionConstructor]
public HelpController()
: this(GlobalConfiguration.Configuration)
{
}
public HelpController(HttpConfiguration config)
{
Configuration = config;
}
/// <summary>
/// GlobalConfiguration By default
/// </summary>
protected static HttpConfiguration Configuration { get; private set; }
....
And problem solved.
I was able to solve this by adding GlobalConfiguration.Configure (WebApiConfig.Register);
in my Application_Start ()
method. Because my application uses OWIN I was registering my APIs only in Startup.Configuration (IAppBuilder app)
.
After some more searching i found this post which also refers to this post
As mentioned in the first post, Glimpse is the culplit, this workaround solved the issue for me:
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<inspectors>
<ignoredTypes>
<add type="Glimpse.AspNet.Inspector.RoutesInspector, Glimpse.AspNet"/>
</ignoredTypes>
</inspectors>
</glimpse>
This is also a known issue and the workaround is described on this Glimpse GitHub Issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With