I am using swashbuckle 5.0.0 rc1 + asp.net core preview 3, getting below error
An error occurred while starting the application.
MissingMethodException: Method not found: 'Void Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware..ctor(Microsoft.AspNetCore.Http.RequestDelegate, Microsoft.AspNetCore.Hosting.IHostingEnvironment, Microsoft.Extensions.Options.IOptions1
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.CreateStaticFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options)
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware..ctor(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options)
Microsoft.Extensions.Internal.ActivatorUtilities+ConstructorMatcher.CreateInstance(IServiceProvider provider)
Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, object[] parameters)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass4_0.b__0(RequestDelegate next)
Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build()
Microsoft.AspNetCore.Hosting.Internal.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Try 5.0.0-rc2
It works! Thanks! Hope it works for @jackselvam as well.
Yes, it's working for me also
I got Swashbuckle.AspNetCore 4.0.1 and I am ending up with the same error:
System.MissingMethodException: Method not found: 'Void Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware..ctor(Microsoft.AspNetCore.Http.RequestDelegate, Microsoft.AspNetCore.Hosting.IHostingEnvironment, Microsoft.Extensions.Options.IOptions`1<Microsoft.AspNetCore.Builder.StaticFileOptions>, Microsoft.Extensions.Logging.ILoggerFactory)'.
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.CreateStaticFileMiddleware(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware..ctor(RequestDelegate next, IHostingEnvironment hostingEnv, ILoggerFactory loggerFactory, SwaggerUIOptions options)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Extensions.Internal.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass4_0.<UseMiddleware>b__0(RequestDelegate next)
at Microsoft.AspNetCore.Builder.ApplicationBuilder.Build()
at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
The thread 0x3a08 has exited with code 0 (0x0).
Exception thrown: 'System.MissingMethodException' in System.Private.CoreLib.dll
An unhandled exception of type 'System.MissingMethodException' occurred in System.Private.CoreLib.dll
Method not found: 'Void Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware..ctor(Microsoft.AspNetCore.Http.RequestDelegate, Microsoft.AspNetCore.Hosting.IHostingEnvironment, Microsoft.Extensions.Options.IOptions`1<Microsoft.AspNetCore.Builder.StaticFileOptions>, Microsoft.Extensions.Logging.ILoggerFactory)'.
Does 4.0.1 support asp.net.core 3.1?
same error here. must update to v5.0.0-rc5 ( the latest rc works for me ) and add UseStaticFiles.
public void ConfigureServices(IServiceCollection services)
{
// configure your applicationi container here then add services as required
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My Api API", Version = "v1" });
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
if (File.Exists(xmlPath))
{
c.IncludeXmlComments(xmlPath);
}
});
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
I cannot use 5.0 as there is no implementation of filterContext.SchemaRegistry.GetOrRegister(type); in IDocumentFilter.
I tried schemaRepository.GetOrAdd(type, type.Name, () => new OpenApiSchema() { Type = type.Name }) but I could not figure out how to use it. It registers types with no properties.
So I stuck with v4 at the moment. Would be nice to have v4 compatible with .net core 3.1 as v5 of swagger is a big mess as I can see the source code so I am not going to use it. This is completely different swagger. The entire api has changed.
Update: We need a good test and I am currently working on that.
@denis-pujdak-adm-it - I think you might be able to get it to work via this, which will add it to the schemaRepository:
context.SchemaGenerator.GenerateSchema(type, context.SchemaRepository);
Also worth noting - this is all described under "Breaking Changes" in the 5.0.0-rc5 release notes:
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/releases/tag/v5.0.0-rc5
Now, if you need to leverage the schema generator within a filter, it should be invoked as follows:
var schema = context.SchemaGenerator.GenerateSchema(typeof(CustomType), context.SchemaRepository);
@domaindrivendev @kylepope-ge Thanks for your help guys. But I ended up with the issue #1452 . Swagger does not generate a schema properly. Very simple example shows it is not working. I got stuck with v4 at the moment.
Try
5.0.0-rc2
Thank you so much @domaindrivendev. Been struggling with this issue after I upgraded my asp.net core solution to .net 5.0. Installing "Swashbuckle.AspNetCore -Version 5.0.0-rc2" fixed it. However neither rc3 nor rc4 worked for me!!.
Most helpful comment
Try
5.0.0-rc2