Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web API Help Pages not loading documentation XML

I'm trying to set up the ASP.NET Help Pages to run in an existing MVC project, though pointing towards the documentation file from a Web API project in the same solution. Convention has the Help Pages running inside the Web API that it's documenting but in this case I want it in a sibling MVC project.

The Web API project outputs its documentation XML file in a folder within the MVC project.

I've installed the Microsoft.AspNet.WebApi.HelpPage NuGet package in the MVC project. This creates a class \Areas\HelpPage\App_Start\HelpPageConfig.cs, and within this class's Register method I've passed the XmlDocumentationProvider the path to the Web API's documentation file.

But when I load the page, it's empty, aside from a title and a placeholder description.

Upon debugging the HelpController.Index method, I can see in the returned IApiExplorer that the _apiDescriptions are empty.

Screenshot from Help Pages running inside MVC project

However, if I install the Help Pages directly into the Web API project and debug the same method, I can see that the _apiDescriptions are now present.

Screenshot from Help Pages running inside Web API project

Can anyone explain what the Web API project is doing or has configured which the MVC project isn't doing or hasn't configured?

like image 570
awj Avatar asked Jan 07 '23 00:01

awj


1 Answers

Just set this up myself, and I think I ran into a similar issue, if i'm reading what you're saying correctly.

Try the following:

  1. Go to Areas\HelpPage\App_Start\HelpPageConfig.cs. Around line 36, you'll want to make sure you uncommented the line as below:

//// Uncomment the following to use the documentation from XML documentation file.
            config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/ApiDocumentation.xml")));
And make sure the path is correct. I happened to put my xml file in the App_Data directory.
  1. Go to Project=>Properties=>Build. Under Output, make sure the "XML documentation file" box is checked, and point it to App_Data\ApiDocumentation.XML (assuming you put it in the same place i did above.
  2. If i remember correctly, i had to make sure i added the .xml file to the project- i had some problems when i tried publishing it to our test server at work and it said the file couldn't be found. After you build, simply go to App_Data, right click on the folder, and add existing item. navigate to App_Data in your file system and select the xml file.

This will hopefully fix your problem!

like image 94
Jamie M Avatar answered Feb 13 '23 23:02

Jamie M