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

Swashbuckle.AspNetCore.SwaggerGen.XmlCommentsParameterFilter exception in combination with .NET8 #2737

Closed
plewam opened this issue Nov 17, 2023 · 7 comments

Comments

@plewam
Copy link

plewam commented Nov 17, 2023

Hi All,

with the release of .NET8 this week I tried to upgrade my restApi. I use Swashbuckle.AspNetCore with version 6.5.0. Once I make a request towards my API I get the below exception resulting in a code 500. When remaining at .NET7 I do not encounter this problem.

Any help would be highly appreciated.

I add my SwaggerGen as below:

builder.Services.AddSwaggerGen(o =>
{
    ConfigureSwaggerGenOptions(o);
    o.DocumentFilter<CustomModelDocumentFilter>();
});

And add my Swagger endpoints like this:

if (app.Environment.IsDevelopment() || app.Environment.IsProduction())
{
    app.UseSwagger();
    app.UseSwaggerUI(o =>
    {
        foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
        {
            o.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
                $"My.App.Namespace - {description.GroupName.ToUpper()}");
        }

        o.RoutePrefix = string.Empty;
    });
}
[ERR] Connection id ""0HMV7B63OMRU5"", Request id ""0HMV7B63OMRU5:00000001"": An unhandled exception was thrown by the application. System.InvalidOperationException: A suitable constructor for type 'Swashbuckle.AspNetCore.SwaggerGen.XmlCommentsParameterFilter' could not be located. Ensure the type is concrete and all parameters of a public constructor are either registered as services or passed as arguments. Also ensure no extraneous arguments are provided.
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.FindApplicableConstructor(Type , Type[], ConstructorInfo& , Nullable`1[]& )
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider, Type , Object[] )
   at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.CreateFilter[TFilter](FilterDescriptor)
   at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.<>c__DisplayClass4_0.<Configure>b__0(FilterDescriptor filterDescriptor)
   at System.Collections.Generic.List`1.ForEach(Action`1)
   at Swashbuckle.AspNetCore.SwaggerGen.ConfigureSwaggerGeneratorOptions.Configure(SwaggerGeneratorOptions)
   at Microsoft.Extensions.Options.OptionsFactory`1.Create(String)
   at Microsoft.Extensions.Options.UnnamedOptionsManager`1.get_Value()
   at Microsoft.Extensions.DependencyInjection.SwaggerGenServiceCollectionExtensions.<>c.<AddSwaggerGen>b__0_1(IServiceProvider s)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite, RuntimeResolverContext)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite, RuntimeResolverContext)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite, TArgument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite, RuntimeResolverContext)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier, ServiceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type)
   at lambda_method1(Closure, Object, HttpContext, IServiceProvider)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.ReflectionMiddlewareBinder.<>c__DisplayClass6_0.<CreateMiddleware>b__0(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1)
@abeven
Copy link

abeven commented Dec 15, 2023

Just ran into this same issue - but only on trimmed compilations. Works fine in .net without trimming.

Would you mind sharing if you did resolve?

@plewam
Copy link
Author

plewam commented Dec 16, 2023

@abeven Sadly I didn't. I remained at NET7 where the issue does not exist. I am quite sure an update is needed for this library.

@soroshsabz
Copy link

soroshsabz commented Jan 18, 2024

ITNOA

@domaindrivendev Any update? or accept PR about this?

@Havunen
Copy link

Havunen commented Feb 17, 2024

This might be fixed in DotSwashbuckle, can you test using it please.
https://github.com/Havunen/DotSwashbuckle
https://www.nuget.org/packages/DotSwashbuckle.AspNetCore

@plewam
Copy link
Author

plewam commented Feb 23, 2024

@Havunen Works like a charm thanks :) Just moved to your new library

@willhuo
Copy link

willhuo commented Mar 22, 2024

come across the same issue
it would bu ok when publish without Trim self-contained deployments and executables

@martincostello
Copy link
Collaborator

Closing as a duplicate of #2747 (though I realise you reported it first).

Sounds like us adding net8.0 will likely fix this.

@martincostello martincostello closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2024
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

6 participants