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.

AspNetCoreToSwaggerGenerator and TestServer (CLI): Cannot resolve IApiDescriptionGroupCollectionProvider (.NET Core 2.0)

See original GitHub issue

When executing the new AspNetCoreToSwaggerGenerator against a .NET Core 2.0 via CLI and TestServer, it cannot resolve IApiDescriptionGroupCollectionProvider:

image

But examining the services object, it clearly has a IApiDescriptionGroupCollectionProvider registration, even with the correct type ($1):

image

Also this works for the .NET Core 2.1 sample project.

Steps to reproduce:

  • Open NSwag.sln
  • Select NSwag.ConsoleCore as startup project and select 2.0:

image

  • In project debug settings, use the command line args: run "MyPath\NSwag\samples\WithoutMiddleware\Sample.AspNetCore20\nswag_assembly.nswag"
  • Run project with all exceptions enabled (break on all exceptions)

The same works for MyPath\NSwag\samples\WithoutMiddleware\Sample.AspNetCore21\nswag_assembly.nswag

/cc @pranavkm @rynowak any idea why this is happening?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
Ghostbirdcommented, Feb 21, 2019

Found that it is the same issue solved here.

When using services.AddMvcCore() instead of services.AddMvC() in Startup.cs:ConfigureServices(), you must do:

services.AddMvcCore().AddApiExplorer()
1reaction
adam-ahcommented, Dec 13, 2019

Nice find, @Ghostbird!

For Google’s sake, if you get

InvalidOperationException: API Explorer not registered in DI.

on startup, the solution is to add

services.AddMvcCore().AddApiExplorer();

in public void ConfigureServices(IServiceCollection services)

Read more comments on GitHub >

github_iconTop Results From Across the Web

No service for type 'Microsoft.AspNetCore.Mvc.ApiExplorer. ...
I can't seem to get swashbuckle to work for my .net core project. "Swashbuckle. ... IApiDescriptionGroupCollectionProvider' has been registered. #299.
Read more >
c# - Cannot resolve parameter 'Microsoft.AspNetCore.Mvc. ...
SwaggerGenerator' can be invoked with the available services and parameters: Cannot resolve parameter 'Microsoft.AspNetCore.Mvc.ApiExplorer.
Read more >
Get started with Swashbuckle and ASP.NET Core
Swashbuckle.AspNetCore.SwaggerGen: a Swagger generator that builds SwaggerDocument objects directly from your routes, controllers, and models.
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