swagger-ui returns 500 after deployment

33,040

Solution 1

When debugging I was using the debug config (Which I had generated XmlComments for: Properties -> build tab -> Output -> XML Documentation File)

I had not done this for my release configuration (duh...) - now everything works

Solution 2

thank you @VisualBean.

As it was not so obvious for me .... how to... a simple image.

In Project > Your Project properties > Build Tab

enter image description here

Solution 3

Swashbuckle is hiding the real error message due to your customErrors setting in web.config. If you set customErrors to off you should get a better error message.

<system.web>
    <customErrors mode="Off"/>
</system.web>

Solution 4

As stated in the accepted answer you have to make sure the XML documentation file output is in bin and not bin\Debug or bin\Release (verify this for all build configurations).

I still got the 500 response because I use multiple XML documentation files. In my SwaggerConfig implementation I include XML documentation files from two projects (the WebApi project itself and a class library that is referenced by the WebApi project):

c.IncludeXmlComments(string.Format(@"{0}\bin\MyWebApiProject.xml", System.AppDomain.CurrentDomain.BaseDirectory));
c.IncludeXmlComments(string.Format(@"{0}\bin\ReferencedProject.xml", System.AppDomain.CurrentDomain.BaseDirectory));

The XML documentation file of the WebApi project was published correctly to the bin folder of the site, however the XML documentation file of the referenced project was not (even though it appears in the bin folder of the compiled project).

So you need to modify the WebApi project file (.csproj) in a text editor and add the following sections at the bottom (replace ReferencedProject):

<PropertyGroup>
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>
  <CopyAllFilesToSingleFolderForMsdeployDependsOn>
    CustomCollectFiles;
    $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
  </CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="CustomCollectFiles">
  <ItemGroup>
    <_CustomFiles Include="..\ReferencedProject\bin\ReferencedProject.xml" />
    <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
      <DestinationRelativePath>bin\%(Filename)%(Extension)</DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

See How do you include additional files using VS2010 web deployment packages? for a full explanation.

Share:
33,040

Related videos on Youtube

VisualBean
Author by

VisualBean

I'm a simple person, with simple needs.. LOTS OF CODEZ!

Updated on June 15, 2021

Comments

  • VisualBean
    VisualBean almost 3 years

    Out of the box configuration works perfectly on my machine, no problems at all.

    But when I deploy to our test environment - I get the following message

    500 : { "Message": "An error has occurred." } /api/swagger/docs/v1

    enter image description here The deployment is to default web site/api

    Im guessing it has something to do with the baseUrl or something like that, but I have no idea of even where to begin.

    My routes work fine within the project - I can call all my webapi endpoints and they respond correctly.

    any help would be much appreciated

  • user2128702
    user2128702 over 7 years
    I had the same problem. My deployment is on azure and I still have the issue. stackoverflow.com/questions/39406820/…
  • VisualBean
    VisualBean almost 7 years
    If you look at the accepted answer, you will probably see, just why this is. :)
  • jb007
    jb007 almost 7 years
    @VisualBean if you are inferring that the solution is to modify the csproj file after changing using the properties window to update the Output > XML, I dont believe that solution is the solution for me, and I had the same issue. INstead, both my debug and release configuration are exactly the same, and dont have anythign specified in XML Documentation file, but still, the debug build will generate that file for debug, and not for release.
  • Karl Gjertsen
    Karl Gjertsen almost 7 years
    My deployment was on azure, but I forgot the simple thing. Change the project properties to create the XML file for release mode too!
  • Karl Gjertsen
    Karl Gjertsen almost 7 years
    The accepted answer is to turn on XML comments in the release settings as well as the debug settings.
  • jb007
    jb007 almost 7 years
    @KarlGjertsen, by "turning on XML" , what exactly do you mean? You mean actually place a value in the "XML Documentation Path"? Because this was not the fix for me, and I just want to know if you have concrete evidence that this is the fix, verses just saying "the fix is XYZ". The fix for me was to just ADD a document to source control, the one that is being derived, instead of depending on msbuild to do it fo rme
  • Karl Gjertsen
    Karl Gjertsen almost 7 years
    I mean checking the box in the project settings so the XML comment file is auto-generated. I had set this for the Dubuffet build, but not the release build.
  • jb007
    jb007 almost 7 years
    Checking that box never worked for me. I had to update manually using the method I described above. Perhaps there are two separate issues, but this was mine and it smelled like the problem presented above
  • Zapnologica
    Zapnologica over 6 years
    What should the directory be?
  • VisualBean
    VisualBean over 6 years
    @Zapnologica it depends on where, you tell swagger config, the files are located.
  • Joe
    Joe over 6 years
    As a variant on this, I added the custom markup to the pubxml file rather than csproj as described in the link below. Also used Include=bin\*.xml which included the xml from all referenced projects without needing to specify them explicitly. See docs.microsoft.com/en-us/aspnet/web-forms/overview/deploymen‌​t/…
  • Seun S. Lawal
    Seun S. Lawal over 4 years
    If the first answer does not work for you. Use this suggestion(turn on custom error mode) to see what is going on in your program. For me, I realized someone had introduced an ambiguous endpoint in one of our API Controllers. The moment I corrected this, we were all fine.
  • Johannes Wentu
    Johannes Wentu about 4 years
    It worked for me, but now the exact same error appears in ALL the Response Bodies of all the methods. "Message": "An error has occurred." Where should I look now? Thanks
  • LarryBud
    LarryBud almost 3 years
    This is a better first step rather than guessing at what the error is!