Reputation: 3707
Working on my first Web API and using Swagger for documentation. I usually publish my Web API locally and then move it to IIS. Inside Visual Studio 2017 I will publish the API as a File System to a folder called C:\PublishedSites\APIName and that is what I did for this API. I then create a site in IIS and copy all the files over.
When I work with the API on my local machine everything works but once I publish locally, move it to my STAGE server, and try to run the API I get and error "Could not load file or assembly" and it's referencing "MyAPI.SwaggerConfig.Register() in C:\TFS\MyAPI\WorkdayAPI\App_Start\SwaggerConfig.cs:51" and that folder location is not even on the STAGE server.
I also noticed that in the Bin folder where I publish my files to it does not have the WorkdayAPI.xml file that Swagger uses for the displaying the Summary and Remarks.
This is what I have in my SwaggerConfig file:
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
c.ApiKey("Api-Token")
.Description("API Key for accessing secure APIs")
.Name("Api-Token")
.In("header");
c.SingleApiVersion("v1", "WorkdayAPI");
c.IncludeXmlComments(string.Format(@"{0}\bin\WorkdayApi.XML",
System.AppDomain.CurrentDomain.BaseDirectory));
// If you want the output Swagger docs to be indented properly, enable the "PrettyPrint" option.
c.PrettyPrint();
})
.EnableSwaggerUi(c =>
{
// If your API supports ApiKey, you can override the default values.
// "apiKeyIn" can either be "query" or "header
c.EnableApiKeySupport("Api-Token", "header");
});
}
}
Anyone have any ideas why it's looking for this SwaggerConfig.cs file? I thought that got compiled in the the MyAPI.dll? Any suggestions on what I need to do?
Upvotes: 0
Views: 1852
Reputation: 41
I think this is probably a build profile issue. When you work on your local machine, you're probably on Debug mode, and when you deploy your Web API it's probably in Release mode.
For Swagger, I suppose you were going into your project properties and checked XML documentation file option in the Build tab ? Do the same thing by choosing the Release profile first in the top dropdown. So when your Web API will be compiled in Release mode, the XML doc file will be generated.
Upvotes: 1