question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger not working in 4.2.0

See original GitHub issue

Greetings:

Today I noticed there was a new version of this awesome library and installed it right away. Just after that my API refused to start, giving me this trace error:

System.ArgumentNullException: Value cannot be null. (Parameter 'provider')
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.CreateScope(IServiceProvider provider)
   at FastEndpoints.Swagger.ValidationSchemaProcessor..ctor()
   at FastEndpoints.Swagger.Extensions.EnableFastEndpoints(AspNetCoreOpenApiDocumentGeneratorSettings settings, Int32 tagIndex, Int32 maxEndpointVersion, Boolean shortSchemaNames)
   at FastEndpoints.Swagger.Extensions.<>c__DisplayClass2_0.<AddSwaggerDoc>b__0(AspNetCoreOpenApiDocumentGeneratorSettings s)
   at Microsoft.Extensions.DependencyInjection.NSwagServiceCollectionExtensions.<>c__DisplayClass0_0.<AddOpenApiDocument>b__0(AspNetCoreOpenApiDocumentGeneratorSettings settings, IServiceProvider services)
   at Microsoft.Extensions.DependencyInjection.NSwagServiceCollectionExtensions.<>c__DisplayClass1_0.<AddOpenApiDocument>b__0(AspNetCoreOpenApiDocumentGeneratorSettings settings, IServiceProvider services)
   at Microsoft.Extensions.DependencyInjection.NSwagServiceCollectionExtensions.<>c__DisplayClass3_0.<AddSwaggerDocument>b__0(IServiceProvider services)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   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.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.AspNetCore.Builder.NSwagApplicationBuilderExtensions.UseOpenApiWithApiExplorerCore(IApplicationBuilder app, Action`1 configure)
   at Microsoft.AspNetCore.Builder.NSwagApplicationBuilderExtensions.UseOpenApi(IApplicationBuilder app, Action`1 configure)
   at Program.<Main>$(String[] args) 

The execution stops at: app.UseOpenApi();

If I remove:
app.UseOpenApi();
app.UseSwaggerUi3();

the api starts and works just fine, this is swagger related only, I think.

Maybe the fault is in my end? Going back to 4.1.0 fixes the problem without changing any code.

Best Regards.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wjaxcommented, May 19, 2022
static IServiceProvider ServiceProvider { get; set; } //set only from .UseFastEndpoints() during startup

Yeah, I think is there

1reaction
dj-nitehawkcommented, May 19, 2022

@desarrollo-ctme & @wjax i believe i’ve figured out what’s happening. most likely you’re calling app.UseOpenApi() before calling app.UseFastEndpoints() like so:

var builder = WebApplication.CreateBuilder();
builder.Services.AddFastEndpoints();
builder.Services.AddSwaggerDoc();

var app = builder.Build();
app.UseAuthorization();
app.UseOpenApi();
app.UseFastEndpoints(); //this reproduces the null reference exception - move this up to fix the issue
app.UseSwaggerUi3(s => s.ConfigureDefaults());
app.Run();

i will add better checks against this and throw a proper error message when the pipeline is configured incorrectly like this.

if that doesn’t solve it for you, please do a repo that has the problem so we can clone it and debug.

thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger is not compatible with Spring 4.2.3 · Issue #1055
I've just updated my spring-boot 1.3.0.RC1 ( also 1.3.0.RELEASE ) app to Spring 4.2.3, and having io.springfox springfox-swagger2 2.2.2.
Read more >
Added Springfox Swagger-UI and it's not working, what am ...
Adding / at the end of url for swagger-ui worked for me. – Abhishek. Dec 10, 2020 at 17:21.
Read more >
Setting Up Swagger 2 with a Spring REST API
In this tutorial, we'll look at Swagger 2 for a Spring REST web service, using the Springfox implementation of the Swagger 2 specification....
Read more >
Swagger causing conflicts with other JS libraries
While Swagger and the Swagger UI are working without issue, it has somehow caused conflicts with the node UI application, causing many JS ......
Read more >
Swagger RESTful API Documentation Specification
A flag to note whether the container allows duplicate values or not. If the value is set to true , then the array...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found