3

I am working on an ASP.NET Core 2.2 API deployed to Azure App Services. I am deploying to a DEV slot.

I am using Swagger, which works fine on my localhost, but when I go to the URL of by DEV slot and use /swagger, I get the error;

FileNotFoundException: Could not find file 'D:\home\site\wwwroot\MyApi.xml 

I have the following in my *.csproj file;

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>  

And when I go to Kudu for the DEV slot, I can see the MyApi.xml file in the /site/wwwroot folder. If I edit it in Kudu, I can see that the content is as expected.

In my project's Startup.cs class --> Configure method, I have;

app.UseStaticFiles(); 

This is similar to the SO post here but in that post, the file was not actually showing up in wwwroot, whereas in my case, it does.

The API otherwise works correctly in that I can use Postman to test all of the APIs endpoints in the DEV slot. It is just that when I try to access DEV slot URL + /swagger from Chrome, I get the FileNotFound exception.

My Startup.cs --> ConfigureServices method has the following;

services.AddSwaggerGen(
    options =>
    {
        // integrate xml comments
        options.IncludeXmlComments(XmlCommentsFilePath);
    });

and the XmlCommentsFilePath method is below;

private static string XmlCommentsFilePath
{
    get
    {
        var basePath = PlatformServices.Default.Application.ApplicationBasePath;
        var fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml";
        return Path.Combine(basePath, fileName);
    }
}

I assume that the Swagger setup is correct since it works locally and the error I get when deployed to the DEV slot is the FileNotFound pointing to D:\home\site\wwwroot\MyApi.xml where that file actually does exist according to Kudu for that slot.

UPDATE 1

I also tried the recommendation for ASP.NET 2.2 in this SO link with no luck.

What am I missing here?

whiskytangofoxtrot
  • 927
  • 1
  • 13
  • 41

0 Answers0