Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to ASP.NET Core 2.0 Preview 2 breaks Swagger UI #438

Closed
cmaslen opened this issue Jul 3, 2017 · 25 comments
Closed

Upgrading to ASP.NET Core 2.0 Preview 2 breaks Swagger UI #438

cmaslen opened this issue Jul 3, 2017 · 25 comments

Comments

@cmaslen
Copy link

cmaslen commented Jul 3, 2017

After upgrading to .NET Core 2.0 Preview 2 Navigating to the default /Swagger route results in the following exception:

System.MissingMethodException: Method not found: 'Void Microsoft.Net.Http.Headers.EntityTagHeaderValue..ctor(System.String)'.
   at Microsoft.AspNetCore.StaticFiles.StaticFileContext.LookupFileInfo()
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.DefaultFilesMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.<Invoke>d__6.MoveNext()

Steps to reproduce

  1. Upgrade .NET Core to 2.0 preview 2. Install latest VS to work with new API.
  2. Create new Web API Project.

Change TargetFramework to netcoreap2.0. Manually edit the project file to update the packages as follows so the site runs:

<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-preview2-final" />

Configure Swagger as per the documentation in this repo's README.md

  1. Navigate to the /swagger route.

Expected outcome

The Swagger UI for the default API in the web project

Actual outcome

The Exception above

@tillig
Copy link

tillig commented Jul 3, 2017

The exception looks like it comes from the static files middleware rather than Swashbuckle. Have you tried specifically adding a reference to the StaticFiles package to ensure you have the latest pinned? There's all sorts of weird stuff that happens when you try to mix release with preview bits. Happened when they were first coming out with netcore also. Work in progress that has breaking changes they may or may not keep in the next release... Painful.

I'd look at all the packages Swashbuckle references and manually add them all to my project. Ensure they're the preview versions. That will force the latest to be used.

If it still doesn't work I'd recommend debugging into Swashbuckle to at least get an exact location of where it's exploding. I'm sure when .NET Core 2 is closer to stable the will be a better compatibility story. Until then, it'd be super helpful to get folks trying out the bleeding edge bits to help with the troubleshooting, too.

@cmaslen
Copy link
Author

cmaslen commented Jul 4, 2017

Hi @tillig,

Explicitly adding a NuGet reference to StaticFiles preview2 worked. Thanks very much for your help. The following are the package references that will make preview 2 work with Swagger UI for anyone who Googles their way to this issue:

<ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-preview2-final" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup>

@cmaslen cmaslen closed this as completed Jul 4, 2017
dudes-come added a commit to JoyOI/ManagementService that referenced this issue Jul 5, 2017
@xperiandri
Copy link

I did not experienced that with latest ASP.NET Core 2.0 packages from CI

@HansBrems
Copy link

I had the same issue and the solution for me was to install the Microsoft.AspNetCore.StaticFiles Nuget package.

@wsun4ipipeline
Copy link

Aetherix, thanks a lot... it's fixed my problem.

@ovation22
Copy link

I had all the same, uninstall/reinstall of Swagger fixed me.

@vdachev
Copy link

vdachev commented Aug 31, 2017

I think it makes sense that the "Swashbuckle.AspNetCore" NuGet package has an explicit dependency on "Microsoft.AspNetCore.StaticFiles".

@elmojo
Copy link

elmojo commented Sep 1, 2017

Adding "Microsoft.AspNetCore.StaticFiles" explicitly didn't work for me. Uninstalling "Swashbuckle.AspNetCore" and reinstalling it DID fix the problem.

@dmitry-pavlov
Copy link

What did the trick for me:

  1. Delete all old files from your deployment folder (I tried with IIS, also works for other hosting types)
  2. Make sure you have these packages in your project file
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" /> 
  </ItemGroup>
  • Replace all Microsoft.AspNetCore.* with Microsoft.AspNetCore.All meta package - see this post for the details.
  • Just case of the side effects, reinstall Swashbuckle.AspNetCore package (no other Swashbuckle.AspNetCore.* needed)
  1. Publish (or deploy by copying the files) to your deployment folder.
  2. Now it should work. 👍

@ghost
Copy link

ghost commented Sep 10, 2017

Aetherix, like wsun4ipipeline your solution did the trick. It fixed my problem.

@hikalkan
Copy link

hikalkan commented Sep 12, 2017

For me, installing Microsoft.AspNetCore.Mvc and Microsoft.AspNetCore.StaticFiles made it working. Thank you all.

@sergiomcalzada
Copy link

Remember to add:

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles();
}

@collinbarrett
Copy link

I'm still struggling with this issue, any other ideas? Thanks.

@sajeshd2008
Copy link

Hi @tillig,

By adding staticFiles nuget it worked for me.Thanks for your help.

@Himansh-Tiwari
Copy link

Thanks Guys,

Installing **

Install-Package Swashbuckle.AspNetCore.SwaggerUI

** worked for me.

@MelbourneDeveloper
Copy link

MelbourneDeveloper commented Jan 10, 2018

I have installed Swashbuckle.AspNetCore.SwaggerUI and am still having this issue. I believe we are off the preview of ASP.NET Core 2.0 though right?

@kaykayes
Copy link

Thanks Hikalkan. Installing Microsoft.AspNetCore.StaticFiles worked for me on vs on mac os high sierra

@springy76
Copy link

springy76 commented Jan 24, 2018

nuget-shit

Let me tell that as polite as possible: I FUCKING HATE THAT FUCKING TRANSITIVE NUGET REFERENCES! [1]

Please anyone tell me which NuGet/VS-Tool will show me that there are old packages (like StaticFiles 1.0.4) which could be updated. Or how I can change that silly "most minor version" preference of transitive package restore.

Ranting some more: In this special case (aspnetcore) I could use Microsoft.AspNetCore.All if it wasn't tied to netcoreapp2.0 -- I am using full .net framework so I cannot use this package.

[1] Of course I don't like the old style either: Where 1001 packages are listed in packages.config and no one knows why any of them is listed there.

@davidfowl
Copy link
Contributor

@springy76 transitive nuget references aren't the problem here. You're just experiencing a version mismatch and a breaking change. This is a just an honest incompatiblity and nothing saves you here.

Here's what could have been done and what still could be done to make this issue fail better (becuse it'll still fail it'll just fail better).

ASP.NET 1.x should set upperbounds on our packages for the next major version. If we did that, you'd get an error that StaticFiles 1.0.x cannot function with ASP.NET Core 2.x.

@vpaulino
Copy link

vpaulino commented Jun 4, 2018

Hi there !

Regarding support to aspnet core 2.1... As you can see on the print screen Im having this issue:

image

Do I real need to add the *all metapackages ?

Does the namespace change ? Why is it broke ?

@quetzalcoatl
Copy link

quetzalcoatl commented Jun 21, 2018

Same here, just like vpaulino - after upgrading to 2.1 build was broken with the same runtime exception:

MissingMethodException: Nie odnaleziono metody: 'Void Microsoft.Net.Http.Headers.EntityTagHeaderValue..ctor(System.String)'.
    Microsoft.AspNetCore.StaticFiles.StaticFileContext.LookupFileInfo()
    Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
    Microsoft.AspNetCore.StaticFiles.DefaultFilesMiddleware.Invoke(HttpContext context)
    Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext)

It turns out that the ctor really ceased to exist. It now takes the new StringSegment instead of plain String, see https://docs.microsoft.com/en-us/dotnet/api/microsoft.net.http.headers.entitytagheadervalue?view=aspnetcore-2.1 . While StringSegment and String are convertible, that's only during compilation. On the assembly side the signature of the constructor has changed, so without recompiling it cannot just be wired up. I think it all boils down to something in your project pulling the static-files in 2.0 instead of 2.1?

@quetzalcoatl
Copy link

Back on topic - yup - Swagger.UI 1.1.0 bases on StaticFiles 1.0.4 and that collides with asp-core 2.1 that upgrades that to static-files-2.1 which has the new construtor style. Well.. that ref wasn't updated for a long time (--"). However, even after updating Swagger to the newest 2.5.0, it still depends on StaticFiles 1.0.4 and still crashes.

So far I've NOT managed to force my projects to use the old library by

<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="[1.0.4,2.1)" />

@quetzalcoatl
Copy link

FYI: I cloned SwaggerUI, updated the ref to 2.1.1, recompiled, and everything works fine.

@RubenDelange
Copy link

Swashbuckle.AspNetCore v3 still has this problem. Any workarounds (apart from what @quetzalcoatl did)?

@rtaylor72
Copy link

What I had to do for V2 and V3 of Swagger was to add a NuGet reference to Microsoft.AspNetCore.StaticFiles 2.1.1. Hope this help!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests