IT TIP

swagger-ui는 배포 후 500을 반환합니다.

itqueen 2020. 10. 28. 21:22
반응형

swagger-ui는 배포 후 500을 반환합니다.


기본 구성은 내 컴퓨터에서 완벽하게 작동하며 전혀 문제가 없습니다.

하지만 테스트 환경에 배포하면 다음 메시지가 표시됩니다.

500 : { "메시지": "오류가 발생했습니다." } / api / swagger / docs / v1

여기에 이미지 설명 입력 배포는 default web site/api

나는 그것이 baseUrl 또는 이와 비슷한 것과 관련이 있다고 생각하지만 어디서 시작 해야할지조차 모릅니다.

내 경로는 프로젝트 내에서 잘 작동합니다. 모든 webapi 엔드 포인트를 호출 할 수 있으며 올바르게 응답합니다.

어떤 도움이라도 대단히 감사하겠습니다


디버깅 할 때 디버그 구성 (내가 XmlComments를 생성 한 속성-> 빌드 탭-> 출력-> XML 문서 파일)을 사용했습니다.

릴리스 구성을 위해이 작업을 수행하지 않았습니다. (duh ...)-이제 모든 것이 작동합니다.


Swashbuckle은 web.config의 customErrors 설정으로 인해 실제 오류 메시지를 숨기고 있습니다. customErrors를 off로 설정하면 더 나은 오류 메시지가 표시됩니다.

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

@VisualBean 감사합니다.

나에게는 그렇게 분명하지 않았기 때문에 .... 방법 ... 간단한 이미지.

프로젝트> 프로젝트 속성> 빌드 탭

여기에 이미지 설명 입력


허용 대답에 명시된 바와 같이 당신은 반드시 XML 문서 파일 출력에 확인해야 이 아닌 빈 \ 디버그 또는 빈 \ 릴리스 (모든 빌드 구성에 대해이를 확인).

여러 XML 문서 파일을 사용하기 때문에 여전히 500 응답을 받았습니다. 내에서 SwaggerConfig의 구현 나는이 개 프로젝트합니다 (WebApi 프로젝트 자체와 WebApi 프로젝트에서 참조하는 클래스 라이브러리)에서 XML 문서 파일을 포함 :

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

WebApi 프로젝트의 XML 문서 파일은 사이트의 bin 폴더에 올바르게 게시되었지만 참조 된 프로젝트의 XML 문서 파일은 그렇지 않았습니다 ( 컴파일 된 프로젝트 의 bin 폴더에 표시 되더라도 ).

따라서 텍스트 편집기에서 WebApi 프로젝트 파일 (.csproj)을 수정하고 맨 아래에 다음 섹션을 추가해야합니다 ( 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>

VS2010 웹 배포 패키지를 사용하여 추가 파일을 어떻게 포함합니까?를 참조하십시오 . 자세한 설명은.


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 여기에 이미지 설명 입력


The accepted answer should be the first thing you try.

그러나 XML 출력이 App_Data \로 이동하도록 설정되어 있고 Swashbuckle이 해당 디렉터리에서 읽도록 구성되었으므로 어떤 방식으로 빌드되는지는 중요하지 않습니다. xml 파일이 '거기에'있을 것입니다. 그럼에도 불구하고 여전히 오류가 발생했습니다 ...

MSDN 포럼 @ enough2012의 답변 에서 찾았습니다 .

게시 대화 상자의 "설정"창에있는 "파일 게시 옵션"에서 "대상에서 추가 파일 제거"를 선택합니다.

매력처럼 일했다!

참고 URL : https://stackoverflow.com/questions/33914842/swagger-ui-returns-500-after-deployment

반응형