swagger-ui returns 500 after deployment

牧云@^-^@ 提交于 2019-11-26 19:47:28

问题


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

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


回答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




回答2:


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>



回答3:


thank you @VisualBean.

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

In Project > Your Project properties > Build Tab




回答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.




回答5:


The issue is that running dotnet publish with -r Release does not produce XML file. However, dotnet publish with -r Debug does in fact produce the file. This explains why people are only getting this issue when they are deploying to environments OTHER than locally, then kicking themselves when the find the exception only occurs on prod.(ITS THE RELEASE) In order to reporoduce, simply run those command locally and view output directory and you should see the issue.

(UPDATE) The fix for me was to actually go into .csproj file and add a line to ensure that the file was copied over always. Diff shown below




回答6:


The accepted answer should be the first thing you try.

However, I have my XML output set to go to App_Data\ and have my Swashbuckle configured to read from that directory, so, it doesn't matter which way it gets built: the xml files are going to 'be there'. Nevertheless, I was still getting the error...

I found over at MSDN's forums @enough2012's answer:

select "Remove additional files at destination" in the "File Publish Options" within the "Settings" pane of the Publish dialog.

Worked like a charm!



来源:https://stackoverflow.com/questions/33914842/swagger-ui-returns-500-after-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!