Closed gereon77 closed 5 years ago
Ok, I will look at this in the next few days, probably on Friday.
Sent from my phone
On 7 Nov 2018, at 15:29, gereon77 notifications@github.com wrote:
I now run in following exception on startup:
MissingMethodException: Method not found: 'Void Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions.OperationFilter(System.Object[])'. Swashbuckle.AspNetCore.Filters.SwaggerGenOptionsExtensions.ExampleFilters(SwaggerGenOptions swaggerGenOptions) SoftwareHub.WebApi.Startup.b20_0(SwaggerGenOptions configuration) in Startup.cs Microsoft.Extensions.Options.ConfigureNamedOptions.Configure(string name, TOptions options) Microsoft.Extensions.Options.OptionsFactory.Create(string name) System.Lazy.CreateValue() System.Lazy.LazyInitValue() Swashbuckle.AspNetCore.SwaggerGen.ConfigureSchemaRegistryOptions..ctor(IServiceProvider serviceProvider, IOptions swaggerGenOptionsAccessor) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope) Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.b0(ServiceProviderEngineScope scope) Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider sp, Type type, Type middleware) lambda_method(Closure , object , HttpContext , IServiceProvider ) SoftwareHub.WebApi.Custom.SwaggerAuthorizedMiddleware.Invoke(HttpContext context) in SwaggerAuthorizedMiddleware.cs Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
It's a bit weird, because just before calling swaggerGenOptions.ExampleFilters() I registrate 2 further custom operation filters and there everything goes fine. Unfortunately your ExampleOperationsFilter is internal so I can't test adding it without your extension.
swaggerGenOptions.OperationFilter<ConsumesOperationFilter>(); // works
swaggerGenOptions.OperationFilter<ApiKeyOperationFilter>(); // works
swaggerGenOptions.ExampleFilters(); // missing method exception
This should hopefully be fixed now.
Please try https://www.nuget.org/packages/Swashbuckle.AspNetCore.Filters/4.4.0 and if it works then close this issue.
Hmm, so I tested this yesterday with a new .NET Core 2.0 Web API and it works fine. 2.1 also works fine.
But when I try and upgrade an existing solution which was using Swashbuckle 3.0 to Swashbuckle 4.0 I'm getting the same exception, and I don't understand why.
Got a .NET Core 2.1 WebApi Project here with upgraded Swashbuckle 4.0 (formerly 3.0) and just updated to Swashbuckle.AspNetCore.Filters/4.4.0 Works like a charme for me.
This should hopefully be fixed now.
Please try https://www.nuget.org/packages/Swashbuckle.AspNetCore.Filters/4.4.0 and if it works then close this issue.
Unfortunately 4.4.0 doesn't help for me.... And I agree... It's a totally strange issue.
Well don't I feel silly. I've spent a few hours scratching my head trying to figure out why 4.4.0 isn't working on a solution at work, and it turns out it is working just fine.
What isn't working at work is the MicroElements.Swashbuckle.FluentValidation package which my work solution is also using.
The code blows up with the same exception at the line c.AddFluentValidationRules();
which happens to be right next to the call to c.ExampleFilters();
Are you also using that package by any chance @gereon77 ?
I'm going to close this issue now, since others have confirmed that 4.4.0 is working fine for them.
No I don't use this package. I guess it correlates to the fact that I am not on pure dot net core. I still reference the full framework because of one of my dependencies...
Ah OK, you're on full framework. I'll reopen and investigate. Which version of the Framework are you using?
@gereon77 Please try https://www.nuget.org/packages/Swashbuckle.AspNetCore.Filters/4.5.0 which should work against .NET Framework 4.6.1.
I try it tomorrow. I use 4.6.1
@mattfrear Unfortunately the problem still exists with Filters 4.5.0 :( when i have time i try to investigate deeper. Maybe u can provide a version where ur filter class is public sealed instead of internal so i don't need to call ur extension method and can call
swaggerGenOptions.OperationFilter<ExamplesOperationFilter>(Array.Empty<object>());
on my own...
Good Afternoon. I also just upgraded from swashbuckle.aspnetcore 3.0.0 to 4.0.1 and swashbuckle.aspnetcore.filters 4.3.1 to 4.5.0 in a .net framework 4.6.1 app. I am getting the above exception.
The csproj contains the following package references:
PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" Condition="'$(TargetFramework)' == 'netstandard1.6' Or '$(TargetFramework)' == 'net461'"
PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="3.0.0" Condition="'$(TargetFramework)' == 'netstandard1.6' Or '$(TargetFramework)' == 'net461'"
PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="4.*" Condition="'$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'net461'"
PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="4.*" Condition="'$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'net461'"
Notice the conditional reference for net461. Doesn't look right to reference both versions of respective packages...
I think the net461 condition should be removed from the 3.0.0 versions
I think the net461 condition should be removed from the 3.0.0 versions
Yes, you’re right, thank you, I don’t know how that slipped through.
I will do it when I get a chance tomorrow.
Sent from my phone
@mattfrear I got the same exception after updating Swashbuckle.AspNetCore
to 4.0.1 and Filters
to 4.5.0.
I'm not sure, probably need to add using Microsoft.Extensions.DependencyInjection
on top of SwaggerGenOptionsExtensions
class. Because the extension method OperationFilter
(and others) was moved to the Microsoft.Extensions.DependencyInjection
namespace.
@gereon77 @bmoregeo please try https://www.nuget.org/packages/Swashbuckle.AspNetCore.Filters/4.5.1 which will be available in the next 5 mins
@barabasishe are you using .NET Core or .NET Framework?
@mattfear .NET Core
The missing method exception is gone but now I get this:
System.InvalidOperationException: 'Unable to resolve service for type 'Swashbuckle.AspNetCore.Filters.RequestExample' while attempting to activate 'Swashbuckle.AspNetCore.Filters.ExamplesOperationFilter'.'
@mattfrear worked for me! Thanks for the quick turnaround!
@gereon77 it sounds like you've probably forgotten to call
services.AddSwaggerExamplesFromAssemblyOf<MyExample>();
or
services.AddSwaggerExamples();
I got the same exception after updating Swashbuckle.AspNetCore to 4.0.1 and Filters to 4.5.0. I'm not sure, probably need to add using Microsoft.Extensions.DependencyInjection on top of SwaggerGenOptionsExtensions class. Because the extension method OperationFilter (and others) was moved to the Microsoft.Extensions.DependencyInjection namespace.
@barabasishe yep, I added that using statement to 4.4.0.
Some things to check
@mattfrear
services.AddSwaggerExamples();
services.AddSwaggerGen(c =>
{
c.ExampleFilters(); //here I get exception
// if I remove previous line, OperationFilter below is succeeded
c.OperationFilter<SomeFilter>();
...
}
MicroElements.Swashbuckle.FluentValidation
ExampleFilters
. Before updating, with 3.0.0, it worked well@barabasishe I hadn't tested with .NET Framework 4.7.1 before, so I just tried it, and it seems to work fine on my local machine.
Have you tried using https://www.nuget.org/packages/Swashbuckle.AspNetCore.Filters/4.5.1 ?
My .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:\code\github\Swashbuckle.AspNetCore.Filters\test\WebApi2.0-461\WebApi.xml</DocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="4.5.1" />
</ItemGroup>
</Project>
I also tried with the latest version of everything:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>C:\code\github\Swashbuckle.AspNetCore.Filters\test\WebApi2.0-461\WebApi.xml</DocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="4.5.1" />
</ItemGroup>
</Project>
It also works fine.
@gereon77 it sounds like you've probably forgotten to call
services.AddSwaggerExamplesFromAssemblyOf<MyExample>(); or services.AddSwaggerExamples();
This helped. Now everything works as expected. I am going to close the issue.
I now run in following exception on startup:
MissingMethodException: Method not found: 'Void Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions.OperationFilter(System.Object[])'. Swashbuckle.AspNetCore.Filters.SwaggerGenOptionsExtensions.ExampleFilters(SwaggerGenOptions swaggerGenOptions) MyProject.Startup.b20_0(SwaggerGenOptions configuration) in Startup.cs
Microsoft.Extensions.Options.ConfigureNamedOptions.Configure(string name, TOptions options)
Microsoft.Extensions.Options.OptionsFactory.Create(string name)
System.Lazy.CreateValue()
System.Lazy.LazyInitValue()
Swashbuckle.AspNetCore.SwaggerGen.ConfigureSchemaRegistryOptions..ctor(IServiceProvider serviceProvider, IOptions swaggerGenOptionsAccessor)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.b 0(ServiceProviderEngineScope scope)
Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.GetService(IServiceProvider sp, Type type, Type middleware)
lambda_method(Closure , object , HttpContext , IServiceProvider )
MyProject.SwaggerAuthorizedMiddleware.Invoke(HttpContext context) in SwaggerAuthorizedMiddleware.cs
Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)